Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs /bin/sh:SET:未找到命令_Reactjs_Macos_Yarnpkg - Fatal编程技术网

Reactjs /bin/sh:SET:未找到命令

Reactjs /bin/sh:SET:未找到命令,reactjs,macos,yarnpkg,Reactjs,Macos,Yarnpkg,我克隆了一个react项目,其中包含以下package.json。在纱线之后,纱线开始给了我以下错误。我尝试了纱线添加反应脚本开始,但仍然不起作用 我正在使用MacOS 有人能帮忙吗 $ yarn start yarn run v1.21.1 $ SET PORT=8000 && react-scripts start /bin/sh: SET: command not found error Command failed with exit code 127. info Vis

我克隆了一个react项目,其中包含以下
package.json
。在
纱线
之后,
纱线开始
给了我以下错误。我尝试了
纱线添加反应脚本开始
,但仍然不起作用

我正在使用MacOS

有人能帮忙吗

$ yarn start
yarn run v1.21.1
$ SET PORT=8000 && react-scripts start
/bin/sh: SET: command not found
error Command failed with exit code 127.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
package.json

{
  "name": "frontend",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@material-ui/core": "^4.9.8",
    "@microsoft/office-js-helpers": "^1.0.2",
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.3.2",
    "@testing-library/user-event": "^7.1.2",
    "@types/react-stripe-elements": "^6.0.4",
    "@uifabric/react-cards": "^0.109.49",
    "axios": "^0.19.2",
    "color": "^3.1.2",
    "cross-storage": "^1.0.0",
    "dva": "^2.4.1",
    "dva-model-creator": "^0.4.3",
    "formik": "^2.1.4",
    "lodash": "^4.17.15",
    "moment": "^2.24.0",
    "monaco-editor": "^0.20.0",
    "node-sass": "^4.13.1",
    "office-ui-fabric-react": "^7.105.4",
    "query-string": "^6.11.1",
    "react": "^16.13.1",
    "react-app-polyfill": "^1.0.6",
    "react-dom": "^16.13.1",
    "react-monaco-editor": "^0.35.0",
    "react-scripts": "3.4.1",
    "react-stripe-elements": "^6.1.1",
    "redux-devtools-extension": "^2.13.8",
    "styled-components": "^5.0.1",    
    "typescript": "^3.8.3",
    "yup": "^0.28.3"
  },
  "scripts": {
    "start": "SET PORT=8000 && react-scripts start",
    "build": "react-scripts --max_old_space_size=8096 build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "@types/color": "^3.0.1",
    "@types/cross-storage": "^0.8.29",
    "@types/jest": "^25.1.4",
    "@types/lodash": "^4.14.149",
    "@types/node": "^13.9.5",
    "@types/query-string": "^6.3.0",
    "@types/react": "^16.9.27",
    "@types/react-dom": "^16.9.5",
    "@types/react-redux": "^7.1.7",
    "@types/styled-components": "^5.0.1",
    "@types/yup": "^0.26.33"
  }
}

我认为您需要的是,在执行命令之前设置环境变量:
PORT=8000 react scripts start
,因为Linux/Unix系统不像Windows那样使用set命令来设置环境变量


如果找不到
react scripts
命令,请使用此命令直接引用包的本地版本:
PORT=8000./node\u modules/.bin/react scripts start
在MacOS上,您不需要
集。将package.json的
start
脚本的内容更改为
PORT=8000 react scripts start

更好的是,为了支持跨操作系统的环境变量设置,您可以使用以下内容。
为此,将依赖项添加到cross env(
Thread install--dev cross env
),然后将
start
脚本重写为
cross env PORT=8000 react scripts start
,在Posixes上,最兼容的是
“env PORT=8000 react scripts start”


这就是为什么这个包存在;它在Windows和Posix系统上都是正确的。

您使用的是什么操作系统?我使用的是Mac操作系统,但这个项目可能是在Windows下开发的。@SoftTimur这是因为react脚本安装在项目的本地,所以它无法识别您试图执行的命令。我以前没有使用过
warn
,但是对于npm,您可以使用
npx react scripts start
来使用本地版本的package@SoftTimur您还可以尝试将
react scripts start
更改为不起作用的
/node\u modules/.bin/react scripts start
;它首先设置了一个变量端口,但没有将其导出到react脚本二进制文件。@AKX你说得对,我在复制和粘贴OP命令时忘记删除
&&