Skip to content

assets:compile doesn't respect NODE_ENV #1395

@y310

Description

@y310

It seems that NODE_ENV=development bundle exec rails assets:precompile ignores NODE_ENV environment variable.

In order to confirm the problem, I added simple debug code to config/webpack/production.js

+if (process.env.NODE_ENV === 'production') {
+  throw 'NODE_ENV: ' + process.env.NODE_ENV;
+}
 process.env.NODE_ENV = process.env.NODE_ENV || 'production'

And here is the result.

/Users/mito/work/webpacker-test% NODE_ENV=development bundle exec rails assets:precompile
yarn install v1.5.1
[1/4] 🔍  Resolving packages...
success Already up-to-date.
✨  Done in 1.25s.
Webpacker is installed 🎉 🍰
Using /Users/mito/work/webpacker-test/config/webpacker.yml file for setting up webpack paths
Compiling…
Compilation failed:


/Users/mito/work/webpacker-test/config/webpack/production.js:2
  throw 'NODE_ENV: ' + process.env.NODE_ENV;
  ^
NODE_ENV: production

In spite of NODE_ENV=development, process.env.NODE_ENV is production.
Probably, it's caused by this line https://github.com/rails/webpacker/blob/master/lib/tasks/webpacker/compile.rake#L24

This is a repository which includes the reproducing code.
https://github.com/y310/webpacker-test

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions