Environment
webpacker 3.0.2
Rails 5.0.1
I have setup webpacker on pre-existing Rails app. Everything is working fine on development env. However while getting app to staging env, webpacker throws an error while compiling.
** Invoke environment
** Execute webpacker:compile
/srv/www/ticketing/releases/20180125210146/node_modules/@rails/webpacker/package/config.js:25
if (config.dev_server) {
^
TypeError: Cannot read property 'dev_server' of undefined
I have also added staging.js on config/webpack folder but that did not solve the issue.
// Content of config/webpack/staging.js
const environment = require('./environment')
module.exports = environment.toWebpackConfig()
@RORingBBK dev_server settings are only applies in development environment, see config/webpacker.yml. Please make a staging environment in config/webpacker.yml as well.
@gauravtiwari Thanks for quick response. I have added settings for staging environment in config/webpacker.ymltoo.
staging:
<<: *default
compile: false
cache_manifest: true
@RORingBBK thanks, that looks right. Could you please share more info on your use case and how have you setup deployment for staging environment? Ideally, NODE_ENV should be production unless developing locally so I am not sure staging env is needed on webpack side.
@gauravtiwari Webpacker should start compiling right after rake assets:precompile is done, right?
Yep, that's correct 馃憤
But the webpacker is not compiling through after rake assets:precompile is executed. Does it need some extra configuration?
Does using gem 'webpacker', git: 'https://github.com/rails/webpacker.git' and using it from master has any link to this issue instead of just using gem 'webpacker', '~> 3.0'?
Could you post your deploy output please - starting from when assets:precompile is run? Yes that doesn't matter much as long as you are on latest 3.x version? Can you run this locally please?
NODE_ENV=production bundle exec rails assets:precompile
[2018-01-29T08:03:43+00:00] INFO: Processing execute[rake assets:precompile] action run (rails::precompile line 40)
[2018-01-29T08:06:08+00:00] INFO: execute[rake assets:precompile] ran successfully
[2018-01-29T08:06:08+00:00] INFO: Processing bash[update-crontab-camplify] action run (whenever::default line 16)
[2018-01-29T08:06:09+00:00] INFO: bash[update-crontab-camplify] ran successfully
[2018-01-29T08:06:09+00:00] INFO: Processing ruby_block[Remove temp directories] action run (opsworks_cleanup::default line 3)
[2018-01-29T08:06:09+00:00] INFO: ruby_block[Remove temp directories] called
[2018-01-29T08:06:09+00:00] INFO: Processing ruby_block[Clean up old chef log files] action run (opsworks_cleanup::default line 11)
[2018-01-29T08:06:09+00:00] INFO: Clean up: There are 12 logs - keeping only 10
[2018-01-29T08:06:09+00:00] INFO: ruby_block[Clean up old chef log files] called
[2018-01-29T08:06:09+00:00] INFO: bash[logdir_existence_and_restart_apache2] sending restart action to service[apache2] (delayed)
[2018-01-29T08:06:09+00:00] INFO: Processing service[apache2] action restart (apache2::default line 29)
[2018-01-29T08:06:11+00:00] INFO: service[apache2] restarted
[2018-01-29T08:06:11+00:00] WARN: Skipping final node save because override_runlist was given
[2018-01-29T08:06:11+00:00] INFO: Chef Run complete in 314.092974501 seconds
[2018-01-29T08:06:11+00:00] INFO: Removing cookbooks/ssh_users/templates/default/sudoers.erb from the cache; it is no longer needed by chef-client.
[2018-01-29T08:06:11+00:00] INFO: Running report handlers
[2018-01-29T08:06:11+00:00] INFO: Report handlers complete
Yeah I am using webpacker 3.0.2.
On running NODE_ENV=production bundle exec rails assets:precompile locally it has executed successfully and compiled all packs.
I was running into a very similar problem today. It appears that the defaults declared in lib/install/config/webpacker.yml do not properly get merged into non-standard environment names (anything besides test, development, or production).
I'm guessing WebpackerConfiguration#defaults should at least return the 'default' configuration when a non-standard environment name is being used. Perhaps something like:
def defaults
@defaults ||= begin
default_config = YAML.load_file(File.expand_path("../../install/config/webpacker.yml", __FILE__))
HashWithIndifferentAccess.new(default_config[env] || default_config['default'])
end
end
The same issue seems to appear in package/config.js.
Fixing these two issues allowed me to work around the problem locally. I would open a PR, except I cannot seem to get the test suite to run. 馃槙
Could you please try 3.3.0?
Most helpful comment
I was running into a very similar problem today. It appears that the defaults declared in lib/install/config/webpacker.yml do not properly get merged into non-standard environment names (anything besides
test,development, orproduction).I'm guessing WebpackerConfiguration#defaults should at least return the
'default'configuration when a non-standard environment name is being used. Perhaps something like:The same issue seems to appear in package/config.js.
Fixing these two issues allowed me to work around the problem locally. I would open a PR, except I cannot seem to get the test suite to run. 馃槙