使用npm 执行package.json 里面的脚本报错,但是 脚本单独拿出来执行不报错

package.json

{
"name": "fe",
"version": "1.0.0",
"description": "前端代码",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev" : "WEBPACK_ENV=dev webpack-dev-server --inline --port 8088"
},
"repository": {
"type": "git",
"url": "git@gitee.com:。。。。。。"
},
"author": "tomxfei",
"license": "ISC",
"devDependencies": {
"css-loader": "^0.28.7",
"extract-text-webpack-plugin": "^3.0.2",
"file-loader": "^1.1.5",
"html-loader": "^0.5.1",
"html-webpack-plugin": "^2.30.1",
"style-loader": "^0.19.0",
"url-loader": "^0.6.2",
"webpack": "^3.8.1",
"webpack-dev-server": "^2.9.4"
},
"dependencies": {}
}

执行 npm run dev报如下错误

```Liuxf@DESKTOP-D3UCHLD MINGW64 /d/fe (fe_v1.0)
$ npm run dev

fe@1.0.0 dev D:\fe
WEBPACK_ENV=dev webpack-dev-server --inline --port 8088

'WEBPACK_ENV' ▒▒▒▒▒ڲ▒▒▒▒ⲿ▒▒▒Ҳ▒▒▒ǿ▒▒▒▒еij▒▒▒
▒▒▒▒▒▒▒▒▒ļ▒▒▒
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! fe@1.0.0 dev: WEBPACK_ENV=dev webpack-dev-server --inline --port 8088
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the fe@1.0.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\75056\AppData\Roaming\npm-cache_logs\2017-11-25T12_16_13_958Z-debug.log

直接执行 WEBPACK_ENV=dev webpack-dev-server --inline --port 8088没有问题``




2个回答

检查了一遍运行脚本并无错误,本人使用的window7环境下的gitbash,本身是支持 linux 命令执行的

问题 已解决 windows下 要加 set 和 &&
"dev" : "set WEBPACK_ENV=dev && webpack-dev-server --inline --port 8088",

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!