sh: SET: 在 `npm start` 中找不到命令

Nek*_*eko 7 node.js npm reactjs npm-install npm-scripts

我正在尝试运行一个反应项目。在我运行命令后: npm start ,它给了我一个错误:

sh: SET: command not found
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! materials-trace@0.1.0 start: `SET PORT=3100 && node scripts/start.js`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the materials-trace@0.1.0 start 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!     /Users/jzhu321/.npm/_logs/2019-04-22T09_29_51_770Z-debug.log
Run Code Online (Sandbox Code Playgroud)

我在以下位置找到了配置package.json

  "scripts": {
    "start": "SET PORT=3100 && node scripts/start.js",
    "build": "node scripts/build.js",
    "test": "node scripts/test.js"
  },
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个问题?

Tha*_*Van 9

Shell 脚本没有SET命令,只有:set

它应该是 :

"start": "set PORT=3100 && node scripts/start.js",
Run Code Online (Sandbox Code Playgroud)

  • 对于跨平台解决方案,请考虑利用 [cross-env](https://github.com/kentcdodds/cross-env) 来设置环境变量。 (2认同)

Lam*_*ack 6

更改您的SET代码set 应该是

 "scripts": {
"start": "set PORT=3100 && node scripts/start.js",
"build": "node scripts/build.js",
"test": "node scripts/test.js"
},
Run Code Online (Sandbox Code Playgroud)

如果有空格,删除该set命令也会导致错误,因此您可以使用sh: 1: PORT: not foundPORT=3100