0

I use webpack 3.1.0, node 9.2.0, command line of windows 10.

Got the error when I run script on package.json.

"scripts": {
"build": "NODE_ENV=production webpack --progress --colors -p",
...
}

I get the errors like below.

13 verbose stack Error: wow_dns@1.0.0 build: `NODE_ENV=production webpack --progress --colors -p`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (C:\Users\sheng\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\index.js:285:16)
13 verbose stack     at EventEmitter.emit (events.js:159:13)
13 verbose stack     at ChildProcess.<anonymous> (C:\Users\sheng\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:159:13)
13 verbose stack     at maybeClose (internal/child_process.js:943:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:220:5)
14 verbose pkgid wow_dns@1.0.0
15 verbose cwd F:\wow\wow_dns
16 verbose Windows_NT 10.0.16299
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\sheng\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "run" "build"

But it would be run through, if I delete "NODE_ENV=production" like:

"scripts": {
"build": "webpack --progress --colors -p",
...
}

It will works. How to setting running environment in with production environment?

Cœur
  • 34,719
  • 24
  • 185
  • 251
user504909
  • 8,049
  • 12
  • 52
  • 97
  • 1
    Possible duplicate of [How can I set NODE\_ENV=production on Windows?](https://stackoverflow.com/questions/9249830/how-can-i-set-node-env-production-on-windows) – Chase Jan 24 '18 at 04:15
  • No that one is on windows shell setting. For me I want put in package.json with one line command. – user504909 Jan 24 '18 at 04:20

3 Answers3

1

In windows, use & to connect two commands, eg:

"scripts": {
  "test": "echo \"Error: no test specified\" && exit 1",
  "serve": "SET NODE_ENV=development& webpack serve --progress --color",
  "build": "SET NODE_ENV=production& webpack --progress --color",
  "serve-old": "webpack-dev-server --watch"
},
Marius
  • 1,013
  • 2
  • 7
  • 16
呆萌妹
  • 11
  • 1
0

Production deployments will vary in many ways, but a standard convention when deploying in production is to define an environment variable called NODE_ENV and set its value to "production".

For setting NODE_ENV you can use any of these methods

method 1: set NODE_ENV in script attribute of the package.json file

Windows :

"scripts": {
  "build": "SET NODE_ENV=production & webpack --progress --color",
  ...
}

Linux or other unix based system :

"scripts": {
  "build": "NODE_ENV=production && webpack --progress --color",
  ...
}

method 2: set NODE_ENV for all node apps

Windows :

set NODE_ENV=production

Linux or other Unix based system :

export NODE_ENV=production

This sets NODE_ENV for the current bash session thus any apps started after this statement will have NODE_ENV set to production.

method 3: set NODE_ENV for current app

NODE_ENV=production node app.js

This will set NODE_ENV for the current app only. This helps when we want to test our apps in different environments.

For more: https://riptutorial.com/node-js/example/10101/setting-node-env--production-

Codemaker
  • 7,952
  • 3
  • 61
  • 53
-2

Please change

"build": "NODE_ENV=production webpack --progress --colors -p"

to

"build": "set NODE_ENV=production;webpack --progress --colors -p"

or

"build": "NODE_ENV=production;webpack --progress --colors -p"

The problem is that once you finish a command you need to give a semicolon to say that command is over.

deepak thomas
  • 1,048
  • 9
  • 21