【问题标题】:sh: SET: command not found in `npm start`sh:SET:在`npm start`中找不到命令
【发布时间】:2019-09-11 12:33:04
【问题描述】:

我正在尝试运行一个反应项目。在我运行命令后: 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

我在package.json 找到了配置:

  "scripts": {
    "start": "SET PORT=3100 && node scripts/start.js",
    "build": "node scripts/build.js",
    "test": "node scripts/test.js"
  },

我该如何解决这个问题?

【问题讨论】:

  • 你能运行命令吗 - npm i

标签: node.js reactjs npm npm-install npm-scripts


【解决方案1】:

SET 更改为set 你的代码应该是

 "scripts": {
"start": "set PORT=3100 && node scripts/start.js",
"build": "node scripts/build.js",
"test": "node scripts/test.js"
},

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

【讨论】:

    【解决方案2】:

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

    应该是:

    "start": "set PORT=3100 && node scripts/start.js",
    

    【讨论】:

    • 对于跨平台解决方案,请考虑使用cross-env 设置环境变量。
    • 正确:package.json 中的“开始”目标使用的是 Windows 语法而不是 Linux shell 语法。在这个例子中,“测试”和“构建”目标调用了 NodeJS,它与平台无关——它们都可以。 “开始”的另一种选择是set PORT=3100...。另一个可能是export PORT=3100...。正如 RobC 所说,另一种选择是使用 cross-env
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-25
    • 2021-02-15
    • 2021-09-11
    • 1970-01-01
    • 2023-03-06
    • 2016-02-08
    相关资源
    最近更新 更多