Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails webpacker for some reason always think NODE_ENV is production despite I use `webpack-dev-server` and set NODE_ENV to development

As title, I am using docker ruby 2.3.5 (ubuntu) environment, despite I have already setup NODE_ENV=development, when I try to intercept the value of process.env.NODE_ENV I still see production, which I can't find anywhere it has been overridden. It only happens in the docker environment but not on my MacOS, not sure whats the reason?

Update: Here is Dockerfile and docker-compose.yml for reference: https://gist.github.com/goodwill/b4e677ccf8fe0079183adeec35218812

Update: This is the error I end up with when running webpacker-dev-server:

04:08:37 webpacker.1 | /app/config/webpack/development.js:20
04:08:37 webpacker.1 |     https: settings.dev_server.https,
04:08:37 webpacker.1 |                               ^
04:08:37 webpacker.1 | 
04:08:37 webpacker.1 | TypeError: Cannot read property 'https' of undefined
04:08:37 webpacker.1 |     at Object.<anonymous> (/app/config/webpack/development.js:20:31)
04:08:37 webpacker.1 |     at Module._compile (module.js:570:32)
04:08:37 webpacker.1 |     at Object.Module._extensions..js (module.js:579:10)
04:08:37 webpacker.1 |     at Module.load (module.js:487:32)
04:08:37 webpacker.1 |     at tryModuleLoad (module.js:446:12)
04:08:37 webpacker.1 |     at Function.Module._load (module.js:438:3)
04:08:37 webpacker.1 |     at Module.require (module.js:497:17)
04:08:37 webpacker.1 |     at require (internal/module.js:20:19)
04:08:37 webpacker.1 |     at requireConfig (/app/node_modules/webpack/bin/convert-argv.js:97:18)
04:08:37 webpacker.1 |     at /app/node_modules/webpack/bin/convert-argv.js:104:17
like image 816
William Yeung Avatar asked Oct 29 '22 21:10

William Yeung


1 Answers

Docker containers will not collect environment variables from your local environment.

Set the environmental variable inside your Dockerfile. For example:

ENV NODE_ENV=development

Alternatively, you can run the container with that environmental variable from the command line:

$ docker run -e NODE_ENV=devlopment mycontainer
like image 159
Justin Collier Avatar answered Nov 15 '22 10:11

Justin Collier