Webpacker: Deploying to "staging" environment required manually setting `public_root_path: public`

Created on 24 Jan 2019  路  6Comments  路  Source: rails/webpacker

Using 4.0.0.rc.2, but didn't notice any relevant changes in the CHANGELOG since that version. So I apologize in advance if I missed it, or if this was user error.

Deploying with nginx and puma, using RAILS_ENV=staging, we experience the following error trace (thrown from puma):

Error during failsafe response: no implicit conversion of nil into String
  ...rbenv/versions/2.5.1/lib/ruby/2.5.0/pathname.rb:411:in `initialize'
  ...rbenv/versions/2.5.1/lib/ruby/2.5.0/pathname.rb:411:in `new'
  ...rbenv/versions/2.5.1/lib/ruby/2.5.0/pathname.rb:411:in `join'
  .../.../shared/vendor/bundle/ruby/2.5.0/bundler/gems/webpacker-c8375ded9bc8/lib/webpacker/configuration.rb:39:in `public_path'
  .../.../shared/vendor/bundle/ruby/2.5.0/bundler/gems/webpacker-c8375ded9bc8/lib/webpacker/configuration.rb:43:in `public_output_path'
  .../.../shared/vendor/bundle/ruby/2.5.0/bundler/gems/webpacker-c8375ded9bc8/lib/webpacker/configuration.rb:47:in `public_manifest_path'
  .../.../shared/vendor/bundle/ruby/2.5.0/bundler/gems/webpacker-c8375ded9bc8/lib/webpacker/manifest.rb:84:in `load'
  .../.../shared/vendor/bundle/ruby/2.5.0/bundler/gems/webpacker-c8375ded9bc8/lib/webpacker/manifest.rb:64:in `data'
  .../.../shared/vendor/bundle/ruby/2.5.0/bundler/gems/webpacker-c8375ded9bc8/lib/webpacker/manifest.rb:71:in `find'
  .../.../shared/vendor/bundle/ruby/2.5.0/bundler/gems/webpacker-c8375ded9bc8/lib/webpacker/manifest.rb:40:in `lookup'
  .../.../shared/vendor/bundle/ruby/2.5.0/bundler/gems/webpacker-c8375ded9bc8/lib/webpacker/manifest.rb:50:in `lookup!'
  .../.../shared/vendor/bundle/ruby/2.5.0/bundler/gems/webpacker-c8375ded9bc8/lib/webpacker/helper.rb:93:in `block in sources_from_pack_manifest'
  .../.../shared/vendor/bundle/ruby/2.5.0/bundler/gems/webpacker-c8375ded9bc8/lib/webpacker/helper.rb:93:in `map'
  .../.../shared/vendor/bundle/ruby/2.5.0/bundler/gems/webpacker-c8375ded9bc8/lib/webpacker/helper.rb:93:in `sources_from_pack_manifest'
  .../.../shared/vendor/bundle/ruby/2.5.0/bundler/gems/webpacker-c8375ded9bc8/lib/webpacker/helper.rb:83:in `stylesheet_pack_tag'

It looked like maybe pathname was choking on this line, being given a nil :public_root_path: https://github.com/rails/webpacker/blob/master/lib/webpacker/configuration.rb#L39

Sure enough, when I added a root path to my webpacker.yml:
public_root_path: public
...it worked and deployed smoothly, even though public is ostensibly the default path.

Here's my config before manually adding public as the root path. (Skimpy, because we're using a set of traditional webpack config files behind webpacker):

default: &default
  source_path: client
  source_entry_path: app/application
  public_output_path: packs
  cache_path: tmp/cache/webpacker
  cache_manifest: false
  compile: false
  check_yarn_integrity: false
  extract_css: true

development:
  <<: *default

  extract_css: false

test:
  <<: *default

  public_output_path: packs-test

staging:
  <<: *default

  cache_manifest: true

production:
  <<: *default

  cache_manifest: true

Our setup works fine when RAILS_ENV=development, regardless of whether I'm using HMR, watching a static dev build, or using prod-mode webpack bundles (minified, gzipped, etc).

Questions/Issues:

  1. Are default root paths missing? Or maybe missing for custom rails environments?
  2. Or, if there is no bug, why did I have to set one in my case, to what I thought was the default anyway?

Most helpful comment

I can confirm that this works, specifically adding:

default: &default
  public_root_path: public
  ...

to webpacker.yml

All 6 comments

We ran into this upgrading from rc.2 to rc.7. Setting public_root_path explicitly resolved it for us.

I can confirm that this works, specifically adding:

default: &default
  public_root_path: public
  ...

to webpacker.yml

Thanks folks, fixed the problems for us as well.
We are in the process of walking away from having special snow-flake envs like "staging" and just run those envs in production so we replicate exact the same behaviour between our production and stage-test apps, but until that this should fix it for us too.

On that subject and Rails being mostly "Convention over configuration" - is it possible to make public_root_path: public the standard option in new and existing rails apps? or is there a strong argument that I miss here, that specifies why we would need to set this variable explicitly?

This is still an issue in 4.0.7. Thank goodness for this ticket--I was tearing my hair out

For anyone else upgrading from v3 to v4, please be sure to review the upgrade guide carefully. One of the items includes tending to differences in config/webpacker.yml.

Could this issue be closed?

Was this page helpful?
0 / 5 - 0 ratings