【问题标题】:Getting issues while installing React Project on Windows system在 Windows 系统上安装 React Project 时遇到问题
【发布时间】:2019-02-21 14:59:03
【问题描述】:

我正在尝试在我的 Windows 系统上安装 React Web 应用程序。它之前工作正常,但是当我重新安装 Windows 时它停止工作。我已经安装了 Node 和 Npm。

当我运行命令npm install 时,它运行良好。但是当我运行命令npm start 时,它会抛出以下错误:

REACT_APP_ENV 未被识别为内部或外部命令

另请参阅附图:

我已经尝试了很多来查找和解决问题,但没有任何效果。

这里是 package.json 文件内容:

{
  "name": "wm-webapp",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "axios": "^0.18.0",
    "gapi-client": "0.0.3",
    "libphonenumber-js": "^1.7.7",
    "moment": "^2.24.0",
    "node-sass": "^4.11.0",
    "react": "^16.7.0",
    "react-bootstrap": "^0.32.4",
    "react-dates": "^18.4.1",
    "react-dom": "^16.7.0",
    "react-facebook-login": "^4.1.1",
    "react-google-login": "^5.0.0",
    "react-places-autocomplete": "^7.2.0",
    "react-redux": "^5.0.7",
    "react-responsive": "^6.1.1",
    "react-router": "^4.3.1",
    "react-router-dom": "^4.3.1",
    "react-router-redux": "^5.0.0-alpha.9",
    "react-scripts": "2.1.3",
    "react-select": "^1.2.1",
    "react-stripe-elements": "^2.0.2",
    "react-table": "^6.8.6",
    "react-toastify": "^4.5.2",
    "redux": "^4.0.1",
    "redux-devtools-extension": "^2.13.7",
    "redux-form": "^8.1.0",
    "redux-form-input-masks": "^1.3.0",
    "redux-logger": "^3.0.6",
    "redux-saga": "^1.0.0",
    "redux-thunk": "^2.3.0",
    "store": "^2.0.12",
    "styled-components": "^4.1.3"
  },
  "scripts": {
    "start:env": "env-cmd .env.${REACT_APP_ENV} react-scripts start",
    "start": "REACT_APP_ENV=dev npm run start:env",
    "start:test": "REACT_APP_ENV=test npm run start:env",
    "build:env": "env-cmd .env.${REACT_APP_ENV} react-scripts build",
    "build": "REACT_APP_ENV=test npm run build:env",
    "build:prod": "REACT_APP_ENV=prod npm run build:env",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "deploy": "aws s3 cp build s3://test.washmix.com/ --recursive --profile washmix",
    "format": "prettier --write --single-quote --tab-width=2 --print-width=80"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ],
  "devDependencies": {
    "axios-mock-adapter": "^1.16.0",
    "env-cmd": "^8.0.2",
    "husky": "^1.3.1",
    "prettier": "^1.16.1"
  }
}

【问题讨论】:

  • 你也可以分享你的 package.json 文件吗?
  • 这是一个 create-react-app 吗?
  • 在运行npm start之前尝试在命令提示符下运行set REACT_APP_ENV=dev
  • @AkashdeepSingh 累了,仍然显示同样的错误

标签: node.js reactjs npm


【解决方案1】:

您必须更改 package.json 中的所有环境变量:

Set NAME_VARIABLE=VALUE 

例如:

"start": "Set REACT_APP_ENV=dev&& npm run start:env",

【讨论】:

  • 这个解决方案终于对我有用了!谢谢
【解决方案2】:

已经迟到了,但对于正在寻找答案的人来说......

对于 Windows (cmd.exe):

'set "REACT_APP_ENV=dev" && npm run start'

对于 Windows(Powershell):

'($env:REACT_APP_ENV = "dev") -and (npm start)'

对于 Linux、macOS(Bash):

'REACT_APP_ENV=dev npm start'

您可以随时使用 process.env.REACT_APP_ENV

获取事物变量

【讨论】:

    【解决方案3】:

    如果您在 Windows 上运行,请记住在命令和 && 之间不要留空格。
    所以启动脚本将是:

    "start-staging":"set REACT_APP_ENV=staging&amp;&amp;react-scripts start"

    【讨论】:

      【解决方案4】:

      在script-> start中,在值的开始处写cross-env。 之后 运行:npm install。

      你准备好了

      【讨论】:

        猜你喜欢
        • 2020-11-09
        • 2015-04-01
        • 2012-09-19
        • 1970-01-01
        • 2015-01-17
        • 2017-01-15
        • 2013-03-20
        • 1970-01-01
        相关资源
        最近更新 更多