运行“npm run build”时,我收到一条错误消息“无法识别‘CI’”

Posted

技术标签:

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

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

    这是我在 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
    

    这是我的 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 【参考方案1】:

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

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

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

【讨论】:

你有什么问题?

以上是关于运行“npm run build”时,我收到一条错误消息“无法识别‘CI’”的主要内容,如果未能解决你的问题,请参考以下文章

Heroku git push heroku master 运行 cd client && npm run build 不停

“npm run build”不是在添加纱线之前运行吗?

npm run build:ValidationError:无效的选项对象。复制插件

运行 npm run build 时出现构建错误

运行 npm run build 时出现构建错误

`npm 错误!运行 `npm ci && npm run build` 时出现 SyntaxError 后的代码 1`