webpacker: Cannot deploy to staging or demo environments
We have a ‘staging’ environment set up in our webpacker.yml:
# Note: You must restart bin/webpack-dev-server for changes to take effect
default: &default
source_path: app/javascript
source_entry_path: packs
public_output_path: packs
cache_path: tmp/cache/webpacker
# Additional paths webpack should lookup modules
# ['app/assets', 'engine/foo/app/assets']
resolved_paths: []
# Reload manifest.json on all requests so we reload latest compiled packs
cache_manifest: false
extensions:
- .coffee
- .erb
- .js
- .jsx
- .ts
- .vue
- .sass
- .scss
- .css
- .png
- .svg
- .gif
- .jpeg
- .jpg
development:
<<: *default
compile: true
# Reference: https://webpack.js.org/configuration/dev-server/
dev_server:
https: false
host: localhost
port: 3035
public: localhost:3035
hmr: false
# Inline should be set to true if using HMR
inline: true
overlay: true
disable_host_check: true
use_local_ip: false
test:
<<: *default
compile: true
# Compile test packs to a separate directory
public_output_path: packs-test
production:
<<: *default
# Production depends on precompilation of packs prior to booting for performance.
compile: false
# Cache manifest.json for performance
cache_manifest: true
source_entry_path: pcl/packs
public_output_path: pcl/packs
staging:
<<: *default
# Staging depends on precompilation of packs prior to booting for performance.
compile: false
# Cache manifest.json for performance
cache_manifest: true
source_entry_path: pcl/packs
public_output_path: pcl/packs
node_modules/@rails/webpacker/lib/install/config/webpacker.yml
does not have a staging environment defined.
We get the following error:
Compiling
Compilation failed:
/home/user/app/shared/node_modules/@rails/webpacker/package/config.js:15
delete defaultConfig.extensions
^
TypeError: Cannot convert undefined or null to object
at Object.<anonymous> (/home/user/app/shared/node_modules/@rails/webpacker/package/config.js:15:3)
at Module._compile (module.js:641:30)
at Object.Module._extensions..js (module.js:652:10)
at Module.load (module.js:560:32)
at tryModuleLoad (module.js:503:12)
at Function.Module._load (module.js:495:3)
at Module.require (module.js:585:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/home/user/app/shared/node_modules/@rails/webpacker/package/rules/babel.js:2:24)
at Module._compile (module.js:641:30)
rake stderr: Nothing written
delete defaultConfig.extensions
is trying to delete keys in staging (because our own Webpacker config has a staging env defined), but is failing because the default file does not take into account staging environment.
Obviously adding staging won’t fix issues for others that have custom name environments.
This is an issue with 3.2.2
.
Works fine in 3.2.1
.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 30 (9 by maintainers)
Thanks @gauravtiwari, I’ve tried deploying my branch to staging env, error message has changed slightly reflecting your changes. Please re-open?
In
node_modules/@rails/webpacker/package/config.js
safeLoad(readFileSync(defaultConfigPath), 'utf8')
has no staging key.@rodloboz Please make sure npm package is updated as well alongside gem.
@martron I can’t reproduce your issue.
RAILS_ENV
is responsible for loading custom configurations and notNODE_ENV
. Made an example repo: https://github.com/gauravtiwari/webpacker-custom-envPlease see screenshots:
Please, could you make an example repo on Github with your issue.
@aldrinmartoq Unfortunately your workaround does not load the “staging” part of
webpacker.yml
. We use that config file to store environment specific key like google analytics or other front end keys.@khmunkhbat My current workaround is this setup in staging:
export RAILS_ENV=staging export NODE_ENV=production
@gauravtiwari I cloned your custom repo and it works as expected on my machine. I also made the repo match my ruby (v2.4.1) and rails (v5.1.4) versions and it continues to compile to public/packs-staging.
I copied
config/webpacker.yml
andconfig/webpack/*
into my own project but the behaviour is still the same; it still compiles to public/packs. I also ran bundle update with no change in behaviour.There’s something in my project that’s causing the issue. I’ll continue to look for differences between it and your sample repo and will let you know if I figure it out.
Please use 3.3.0
see #1272 and #1265