Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot deploy to staging or demo environments #1274

Closed
taylorwilliams opened this issue Feb 15, 2018 · 30 comments
Closed

Cannot deploy to staging or demo environments #1274

taylorwilliams opened this issue Feb 15, 2018 · 30 comments

Comments

@taylorwilliams
Copy link

taylorwilliams commented Feb 15, 2018

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.

@doits
Copy link
Contributor

doits commented Feb 16, 2018

see #1272 and #1265

@gauravtiwari
Copy link
Member

Please use 3.3.0

@taylorwilliams
Copy link
Author

taylorwilliams commented Mar 5, 2018

Thanks @gauravtiwari, I've tried deploying my branch to staging env, error message has changed slightly reflecting your changes. Please re-open?

Compilation failed:

/home/user/app/shared/node_modules/@rails/webpacker/package/config.js:16
    delete defaults.extensions
    ^

TypeError: Cannot convert undefined or null to object
    at getConfig (/home/user/app/shared/node_modules/@rails/webpacker/package/config.js:16:5)
    at Object.<anonymous> (/home/user/app/shared/node_modules/@rails/webpacker/package/config.js:27:18)
    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:35)
rake stderr: Nothing written

@anthony-robin
Copy link

Same here with the command RAILS_ENV=staging bin/rails webpacker:compile :(

@gauravtiwari
Copy link
Member

Have you upgraded npm package? yarn add @rails/webpacker

@taylorwilliams
Copy link
Author

@gauravtiwari, yeah, upgraded to 3.3.0. Further to this, delete defaults.extensions is only available in your latest code.

@gauravtiwari
Copy link
Member

Yep but it returns a default env if both NODE_ENV and RAILS_ENV is not defined in webpacker.yml - https://github.com/rails/webpacker/blob/master/package/env.js#L20

Here is a output from new rails app with webpacker 3.3.0

screen shot 2018-03-05 at 12 35 13

screen shot 2018-03-05 at 12 37 14

@akaspick
Copy link

akaspick commented Mar 5, 2018

I'm having the same issue. I've added a staging section to webpacker.yml and a staging.js file and am running RAILS_ENV=staging bin/rails webpacker:compile

Getting the same error as @taylorwilliams

/home/deploy/myapp/releases/343/node_modules/@rails/webpacker/package/config.js:18
    delete defaults.extensions

I'm using 3.3.0

@akaspick
Copy link

akaspick commented Mar 5, 2018

In node_modules/@rails/webpacker/package/config.js safeLoad(readFileSync(defaultConfigPath), 'utf8') has no staging key.

@taylorwilliams
Copy link
Author

taylorwilliams commented Mar 5, 2018

What @akaspick said.. so when it tries to delete the keys, in our non-standard environment, staging; it's not able too because the non-standard environment doesn't exist in the default config.

@akaspick
Copy link

akaspick commented Mar 5, 2018

So the contents of defaultConfigPath ('../lib/install/config/webpacker.yml') don't contain a staging key (that file is part of the webpacker module), but the env variable is set to staging.

https://github.com/rails/webpacker/blob/master/package/config.js#L12

The next line const app = safeLoad(readFileSync(configPath), 'utf8')[env] is completely fine though as it's referring to the the apps config file which has a staging key. Looks like defaults should be falling back to the production env or ignoring the defaults?

@gauravtiwari
Copy link
Member

@taylorwilliams @akaspick Thanks, I see. Right, it's bit confusing I am going to take a look again in the evening. Technically, on NODE/JS side NODE_ENV has special meaning, for example lot of packages uses development or production (but not staging) to identify what sort of optimisations/tools they should provide (example: React). So, it would probably make sense to stick with standard environment as NODE_ENV

@gauravtiwari gauravtiwari reopened this Mar 5, 2018
@khmunkhbat
Copy link

khmunkhbat commented Mar 7, 2018

Is there any progress?(webpacker 3.3.0)

I've got same error.

.../node_modules/@rails/webpacker/package/config.js:16
delete defaults.extensions
^

TypeError: Cannot convert undefined or null to object

@aldrinmartoq
Copy link

@khmunkhbat My current workaround is this setup in staging:

export RAILS_ENV=staging
export NODE_ENV=production

@Systho
Copy link
Contributor

Systho commented Mar 7, 2018

@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.

@ismasan
Copy link

ismasan commented Mar 22, 2018

I'm getting this too (Webpacker 3.3.1) @aldrinmartoq's trick doesn't seem to fix it.

@gauravtiwari
Copy link
Member

Just released 3.4.0 and there is some documentation added in README. Please try it out and report your feedback.

@martron
Copy link

martron commented Apr 4, 2018

Tested with 3.4.3 and a staging configuration and the compilation failed error is resolved.

However, with the configuration:

staging:
  # Compile packs to a separate directory
  public_output_path: staging-packs

the command output states Compiled all packs in public/staging-packs but the files actually get compiled into public/packs. I believe this is because webpack_env no longer passes along the NODE_ENV in the call to ./bin/webpack.

I can work around it by renaming the folder in my deploy script after it's been compiled but it does indicate that at the least public_output_path: packs-staging isn't well supported in the current release.

@rodloboz
Copy link

rodloboz commented Apr 4, 2018

I've tested with 3.4.3 and it still has the same compilation error.

/tmp/build_e6fb42213c0638c04c0ea31fc08445e2/node_modules/@rails/webpacker/package/config.js:16
           delete defaults.extensions
           ^
       
       TypeError: Cannot convert undefined or null to object
           at getConfig (/tmp/build_e6fb42213c0638c04c0ea31fc08445e2/node_modules/@rails/webpacker/package/config.js:16:5)
           at Object.<anonymous> (/tmp/build_e6fb42213c0638c04c0ea31fc08445e2/node_modules/@rails/webpacker/package/config.js:27:18)
           at Module._compile (module.js:652:30)
           at Object.Module._extensions..js (module.js:663:10)
           at Module.load (module.js:565:32)
           at tryModuleLoad (module.js:505:12)
           at Function.Module._load (module.js:497:3)
           at Module.require (module.js:596:17)
           at require (internal/module.js:11:18)
           at Object.<anonymous> (/tmp/build_e6fb42213c0638c04c0ea31fc08445e2/node_modules/@rails/webpacker/package/rules/babel.js:2:35)
       
 !
 !     Precompiling assets failed.

@gauravtiwari
Copy link
Member

gauravtiwari commented Apr 5, 2018

@rodloboz Please make sure npm package is updated as well alongside gem.

yarn add @rails/webpacker

@martron I can't reproduce your issue. RAILS_ENV is responsible for loading custom configurations and not NODE_ENV. Made an example repo: https://github.com/gauravtiwari/webpacker-custom-env

Please see screenshots:

screen shot 2018-04-05 at 09 00 34

screen shot 2018-04-05 at 09 00 49

Please, could you make an example repo on Github with your issue.

@taylorwilliams
Copy link
Author

Thanks all for efforts :)

@rodloboz
Copy link

rodloboz commented Apr 5, 2018

@gauravtiwari Thanks for your reply. Updating npm worked for me :)

@martron
Copy link

martron commented Apr 5, 2018

@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 and config/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.

@gauravtiwari
Copy link
Member

@martron Are you using react_on_rails?

@martron
Copy link

martron commented Apr 5, 2018

@gauravtiwari no but webpacker-react is in the gemfile. I did remove it, bundle installed and ran assets:precompile but that didn't change anything.

@lucasdeassis
Copy link

updated "@rails/webpacker": "^3.5.3" and gem 'webpacker', '~> 3.5' and it's working fine now

thanks, guys.

@nozpheratu
Copy link

I still have this issue with 3.5.5.

The following does not seem to use the configuration in config/webpack/staging.js....?

RAILS_ENV=staging NODE_ENV=staging bundle exec rails assets:precompile

@akaspick
Copy link

@nozpheratu Your NODE_ENV should be production.

@nozpheratu
Copy link

@akaspick Tried that, in either case it's using the settings in config/webpack/production.js instead of config/webpack/staging.js.

@ndesorden
Copy link

ndesorden commented Sep 14, 2018

I still have this issue with 3.5.5.

The following does not seem to use the configuration in config/webpack/staging.js....?

RAILS_ENV=staging NODE_ENV=staging bundle exec rails assets:precompile

Same here, NODE_ENV, RAILS_ENV to staging with gem webpacker & @rails/webpacker 3.5.5.
I've a staging entry in webpacker.yml and for compilation webpacker not using staging.js, always using production.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests