【问题标题】:When runing 'npm run build' I get an error that says "'CI' is not recognized"运行“npm run build”时,我收到一条错误消息“无法识别‘CI’”
【发布时间】:2021-04-21 13:20:26
【问题描述】:

我正在处理一个项目,当我尝试运行 npm run build 时,我收到一条错误消息,提示“'CI 无法识别”。我一直在寻找答案,但我找不到任何东西。

  1. 这是我在 gitbash 中得到的:

     'CI' is not recognized as an internal or external command,
    operable program or batch file.
    npm ERR! code ELIFECYCLE
    npm ERR! errno 1
    npm ERR! barhop@0.1.0 prebuild: `CI=true react-scripts test --colors`
    npm ERR! Exit status 1
    npm ERR!
    npm ERR! Failed at the barhop@0.1.0 prebuild 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!     C:\Users\Juan Mireles\AppData\Roaming\npm-cache\_logs\2021-01-16T20_05_42_295Z-debug.log
    
  2. 这是我的 package.json:

    {
      "name": "project",
      "version": "0.1.0",
      "private": true,
      "dependencies": {
        "@testing-library/jest-dom": "^5.11.6",
        "@testing-library/react": "^11.2.2",
        "@testing-library/user-event": "^12.2.2",
        "enzyme": "^3.11.0",
        "enzyme-adapter-react-16": "^1.15.5",
        "enzyme-to-json": "^3.6.1",
        "react": "^17.0.1",
        "react-dom": "^17.0.1",
        "react-placeholder-image": "^0.1.8",
        "react-router-dom": "^5.2.0",
        "react-scripts": "4.0.1",
        "router": "^1.3.5",
        "serve": "^11.3.2",
        "web-vitals": "^0.2.4"
      },
      "scripts": {
        "start": "react-scripts start",
        "prebuild": "CI=true react-scripts test --colors",
        "build": "react-scripts build",
        "test": "react-scripts test",
        "eject": "react-scripts eject",
        "predeploy": "npm run build",
        "deploy": "vercel --prod"
      },
      "eslintConfig": {
        "extends": [
          "react-app",
          "react-app/jest"
        ]
      },
      "browserslist": {
        "production": [
          ">0.2%",
          "not dead",
          "not op_mini all"
        ],
        "development": [
          "last 1 chrome version",
          "last 1 firefox version",
          "last 1 safari version"
        ]
      }
    }
    

【问题讨论】:

  • 这不是您在 Windows 中设置环境变量的方式。如果您需要跨平台运行脚本,请参见例如npmjs.com/package/cross-env

标签: reactjs npm build continuous-integration


【解决方案1】:

如果您在 Windows 上运行,则需要更改预构建。

"prebuild": "set CI=true&react-scripts test --colors",

https://create-react-app.dev/docs/running-tests/#on-your-own-environment

【讨论】:

  • 你有什么问题?
猜你喜欢
  • 2021-03-03
  • 2022-06-22
  • 2022-01-23
  • 2019-05-20
  • 2019-04-14
  • 1970-01-01
  • 2019-11-15
  • 1970-01-01
  • 2017-10-05
相关资源
最近更新 更多