-
I made my way through the upgrade docs, upgrading from Webpacker 5 through to Shakapacker 7. Quite a few bumps along the way, but I got there. Now after completing the migration, deployment to our staging environment is broken because the Shakapacker compile fails. Currently I have the development, test and production environments defined in config/shakapacker.yml. When I manually run the asset precompile task, Shakapacker correctly fallsback to
When I deploy via Capistrano, I again see Shakapacker falling back to
However, the following error is then encountered and the deployment fails:
The error originates from
For staging environment on Webpacker 5 we had to manually set The same error occurs when I add a copy of the production config as "staging" to config/shakapacker.yml. We have a nearly-default
What have I overlooked? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
I found a solution by re-instating the The Custom Rails Environments section of the docs does not mention this as a requirement, and almost implies that Shakapacker takes care of this conversion from RAILS_ENV to correct NODE_ENV for you. If my interpretation is correct, perhaps I have some other configuration error that prevents this working.
The updated webpack.config.js sets const { generateWebpackConfig, merge } = require('shakapacker')
const webpack = require('webpack')
if (['development', 'test', ].includes(process.env.NODE_ENV)) {
process.env.NODE_ENV = 'development'
}
else {
process.env.NODE_ENV = 'production'
}
const webpackConfig = generateWebpackConfig()
const customConfig = {
devServer: {
watchFiles: {
options: {
ignored: '**/.*'
}
}
},
plugins: [
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
})
]
}
module.exports = merge(webpackConfig, customConfig) Still, I'd be interested to hear if I am doing this correctly. |
Beta Was this translation helpful? Give feedback.
-
@jpwilksch I'm glad that you found a solution that works for you. The relevant part of our documentation from the section you linked to is:
To clarify, Shakapacker supports custom |
Beta Was this translation helpful? Give feedback.
@jpwilksch I'm glad that you found a solution that works for you.
The relevant part of our documentation from the section you linked to is:
To clarify, Shakapacker supports custom
RAILS_ENV
values, but Shakapacker does not support customNODE_ENV
values because webpack does not support customNODE_ENV
values.