ShakaCode | ShakaCode Blog | Rails On Maui Blog | Rails | ReactJs | JavaScript | Webpack | Productivity |

'NODE_ENV' is not recognized as an internal or external command operable program or batch file


I’m on Windows. The gem and the dependencies installed successfully, matched versions and ran foreman start -f I can see the webpack folder in the app/assets, but the foreman kills all processes and exits with code 1 with the above mentioned error.
Looking at the source code, I can see a few different webpack files and they all are different, while there is only one with me after the installation. What am I missing? How can I make NODE_ENV available in Rails, if this won’t work:
plugins: [
new webpack.EnvironmentPlugin({
NODE_ENV: ‘development’, // use ‘development’ unless process.env.NODE_ENV is defined
DEBUG: false,
new ManifestPlugin({ fileName: manifest, writeToFileEmit: true }),


Your question is not clear. Any environment can be made available in Rails by editing the appropriate Procfile used to start Rails. You edit the line in the Procfile to set the ENV value.

For example:

You can do something like this on line 6:

rails: NODE_ENV=production rails s -b


I have added the line in the, but this is the output I am getting now:

12:16:35 web.1    | started with pid 15380
12:16:35 rails.1  | unknown command: NODE_ENV=development rails s -b
12:16:35 client.1 | started with pid 14164
12:16:36 client.1 | (in c:/Users/akolybelnikov/OneDrive/finalp/Fruitbom)
12:16:50 web.1    | [2017-07-04 12:16:50] INFO  WEBrick 1.3.1
12:16:50 web.1    | [2017-07-04 12:16:50] INFO  ruby 2.2.4 (2015-12-16) [i386-mingw32]
12:16:50 web.1    | [2017-07-04 12:16:50] INFO  WEBrick::HTTPServer#start: pid=6892 port=3000
12:16:51 client.1 | yarn run v0.24.6
12:16:51 client.1 | $ NODE_ENV=development webpack -w --config webpack.config.js
12:16:51 client.1 | 'NODE_ENV' is not recognized as an internal or external command,
12:16:51 client.1 | operable program or batch file.
12:16:51 client.1 | error Command failed with exit code 1.
12:16:51 client.1 | info Visit for documentation about this command.
12:16:52 client.1 | exited with code 1
12:16:52 system   | sending SIGKILL to all processes
12:16:52 system   | sending SIGKILL to web.1 at pid 15380
12:16:52 system   | sending SIGKILL to rails.1 at pid

My has the following lines in it:

web: rails s -p 3000

rails: NODE_ENV=development rails s -b

client: sh -c 'rm -rf public/webpack/development/* || true && cd client && bundle exec rake react_on_rails:locale && yarn run build:development'

It’s not working.


Your problem is windows based. My team doesn’t use Windows. We need other windows users to help you.


Thanks for guidance. I have set the node environment with cross-env package like so:

"scripts": {
    "build:test": "cross-env NODE_ENV=test webpack --config webpack.config.js",
    "build:production": "cross-env NODE_ENV=production webpack --config webpack.config.js",
    "build:development": "cross-env NODE_ENV=development webpack -w --config webpack.config.js"

so that the .env-related error has been tackled.

However the webpack is failing the build anyways and I have difficulties finding the reason. Here is the output:

20:20:57 web.1    | started with pid 2972
20:20:57 client.1 | started with pid 4080

20:21:16 web.1    | [2017-07-11 20:21:16] INFO  WEBrick 1.3.1
20:21:16 web.1    | [2017-07-11 20:21:16] INFO  ruby 2.2.4 (2015-12-16) [i386-mingw32]
20:21:16 web.1    | [2017-07-11 20:21:16] INFO  WEBrick::HTTPServer#start: pid=10452 port=3000
20:21:17 client.1 | yarn run v0.24.6
20:21:17 client.1 | $ cross-env NODE_ENV=development webpack -w --config webpack.config.js
20:21:18 client.1 | Webpack dev build for Rails
20:21:18 client.1 |
20:21:18 client.1 | Webpack is watching the files…
20:21:18 client.1 |
20:21:19 client.1 | exited with code 5
20:21:19 system   | sending SIGKILL to all processes
20:21:19 system   | sending SIGKILL to web.1 at pid 2972
20:21:19 web.1    | exited with code 0

Here is what I have in the webpack.config.js right now, and I have already tried to change the output in many different ways:

  output: {
    filename: 'main.js',
    path: __dirname + '/../app/assets/webpack'

Have you had any experiences with similar issues? Unfortunately webpack’s code 5 is not elaborate enough to see where exactly the build fails.