1

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
  • 37,241
  • 25
  • 195
  • 267
user504909
  • 9,119
  • 12
  • 60
  • 109
  • 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

2 Answers2

2

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,053
  • 2
  • 7
  • 16
呆萌妹
  • 21
  • 2
-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,118
  • 9
  • 23