【问题标题】:Treating warnings as errors because process.env.CI = true. Failed to compile将警告视为错误,因为 process.env.CI = true。编译失败
【发布时间】:2020-10-21 02:40:08
【问题描述】:

我正在开发一个用于自学目的的 react-weather 应用程序。 在 gh-pages 中部署相同的内容。
网址
https://davisraimon.github.io/react-weather/
回购
https://github.com/davisraimon/react-weather

当试图将我的应用程序与 Travis Ci 集成时,我收到如下错误。 它说我必须更改一些名为 Process.env.CI 的环境变量。

$ git clone --depth=50 --branch=master https://github.com/davisraimon/react-weather.git davisraimon/react-weather
nvm.install
4.18s$ nvm install stable
cache.1
Setting up build cache
cache.npm
$ node --version
v14.4.0
$ npm --version
6.14.5
$ nvm --version
0.35.3
install.npm
13.21s$ npm ci 
7.45s$ npm run build
> react-weather@0.1.0 build /home/travis/build/davisraimon/react-weather
> react-scripts build
Creating an optimized production build...
Treating warnings as errors because process.env.CI = true.
Most CI servers set it automatically.
Failed to compile.
./src/components/form.component.js
  Line 1:17:  'Component' is defined but never used  no-unused-vars
./src/App.js
  Line 2:8:    'logo' is defined but never used              no-unused-vars
  Line 8:7:    'API_key' is assigned a value but never used  no-unused-vars
  Line 37:5:   Expected a default case                       default-case
  Line 53:14:  Expected '===' and instead saw '=='           eqeqeq
  Line 69:20:  Expected '===' and instead saw '=='           eqeqeq
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! react-weather@0.1.0 build: `react-scripts build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the react-weather@0.1.0 build 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!     /home/travis/.npm/_logs/2020-06-30T17_45_07_887Z-debug.log
The command "npm run build" exited with 1.
cache.2
store build cache

我在 .travis.yml 文件中添加了环境变量。

env:
    process.env.CI : false

仍然显示相同的错误。

谁能帮我摆脱这种情况...

【问题讨论】:

  • 是的....当我这样做时,它将完美地工作。谢谢

标签: reactjs deployment continuous-integration travis-ci github-pages


【解决方案1】:
  "scripts": {
    "start": "react-scripts start",
    "build": "CI=false && react-scripts build",  // Add CI=False here
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },

【讨论】:

  • 非常感谢您
【解决方案2】:

对我来说,解决方案是:

env: 
  CI: false

【讨论】:

    【解决方案3】:

    对我来说,用 CI='' npm run build 替换 npm run build 是可行的。

    【讨论】:

      【解决方案4】:

      在我的具体情况下,我使用的是 Netlify,所以我所做的只是在 Netlify 的面板中设置 ENV 变量:

      • 选择网站设置标签
      • 选择构建和部署
      • 向下滚动到环境变量,然后按编辑变量
      • 填入 Key = CI 和 Value = false
      • 按保存并触发新部署

      【讨论】:

        【解决方案5】:

        按照以下步骤,您的问题将得到解决:

        • 选择站点设置选项卡
        • 选择构建和部署
        • 向下滚动到环境变量,选择编辑变量
        • 填入 Key = CI 和 Value = false
        • 按清除缓存并重新部署

        ...玩得开心。

        【讨论】:

          【解决方案6】:

          就我而言,我试图通过 GitHub 存储库将 React 应用程序部署到 Azure 静态网页 这 环境: CI:错误

          工作就像一个魅力。 只是一个简短的说明。这适用于在 GitHub 操作中定义 CI 流程的 yaml。 env 元素没有缩进(与名称同级:)

          【讨论】:

            【解决方案7】:

            如果您想在部署期间处理测试,则需要 CI=true,但可以通过 package.json 设置标志轻松存档(如果您的 dockerfile 已经设置 ENV CI=true,您可以将其删除)

             "scripts": {
                "start": "react-scripts start",
                "build": "react-scripts build",
                "test": "CI=true react-scripts test"
              }
            

            【讨论】:

              【解决方案8】:

              在 yml 文件中的 Gitlab CI 作业中,在我的作业中添加以下脚本对我有用。

              script:
              - CI=false yarn run build
              

              【讨论】:

                猜你喜欢
                • 2021-09-08
                • 2020-10-06
                • 2021-07-18
                • 1970-01-01
                • 2020-08-21
                • 1970-01-01
                • 2021-09-12
                • 1970-01-01
                • 1970-01-01
                相关资源
                最近更新 更多