繁体   English   中英

在 windows 命令行/ package.json 中设置环境

[英]Set env in windows command line/ package.json

windows上运行react应用程序时遇到问题。

该应用程序最初设置为在macOS上运行。
以下是错误消息和package.json文件。

问题:如何为 windows 启动和构建PORT

package.json

{
  "name": "tradingview-finnhub",
  "private": true,
  "dependencies": {
    "react": "^16.12.0",
    "react-dom": "^16.12.0",
    "react-scripts": "3.4.0",
    "request-promise": "^4.2.5"
  },
  "scripts": {
    "start": "PORT=8080 react-scripts start",
    "build": "PORT=8080 react-scripts build"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

错误信息

'PORT' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! tradingview-finnhub@ start: `PORT=8080 react-scripts start`
npm ERR! Exit status 1

您只需要在 PORT=8080 之前添加set并在其之后添加&

它会是这样的:

"scripts": {
    "start": "set PORT=8080 & react-scripts start",
    "build": "set PORT=8080 & react-scripts build"
  },

问题是您需要在运行 react-script 之前设置 PORT 的环境变量,我给出的解决方案就是这样做的。 有关更多信息,您可以查看:

https://superuser.com/questions/79612/setting-and-getting-windows-environment-variables-from-the-command-prompt

如何在 Windows CMD 中的一行中运行两个命令?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM