因为 process.env.CI = true,将警告视为错误。编译失败。

61

我正在制作一款用于自学的react天气应用程序。已将其部署在gh-pages上。
URL
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

仍然显示相同的错误。

有人可以帮我摆脱这种情况吗?


是的...当我这样做时,它会完美地运行。谢谢。 - Davis Raimon
对于未来的读者,process.env是包含所有环境变量的Node变量。在.travis.yml文件中,您应该只使用变量名称,例如CI,而不需要使用process.env - Code-Apprentice
16个回答

0
在 Gitlab CI 的 yml 文件中,将以下脚本添加到我的作业中对我起了作用。
script:
- CI=false yarn run build

0

我正在使用GitLab CI和Yarn,这对我有效:

  script: 
    - CI=false yarn build


0

你必须修复React中的警告,这就是为什么它不允许你部署的原因。


0
在我的情况下,我试图通过 GitHub 存储库将 React 应用部署到 Azure 静态网页上。
env: CI: false 非常顺利地完成了。 只是一个快速的提示。这是应用于在 GitHub 操作中定义 CI 过程的 yaml。 env 元素没有缩进(与 name: 处于同一级别)。

请问您能具体说明一下吗?在yml文件的哪个位置? - Ricardo Álvarez
如果你的设置都是一样的话,它应该位于你的 Github 存储库中的“Actions”选项卡下的“Azure Static Web Apps CI/CD”中。Yaml 的链接就在标题(Azure Static Web Apps CI/CD)下面。 - ivlad

0
对我来说,我正在部署一个ReactJs项目,遇到了CI错误。 我在Netlify中添加了一个环境变量。 添加的变量名是:CI,值为:false。
然后Netlify忽略了这些错误并进行了构建。
Netlify添加环境变量选项:

enter image description here


0
jobs:
  build:
    name: Build ⛏️
    runs-on: ubuntu-latest
    steps: 
      - name: Checkout Repository
        uses: actions/checkout@main
      - name: Install dependencies
        run: npm ci --legacy-peer-deps
      - name: Build dependencies
        run: npm run build
        env: 
          CI: false  // Here I added CI = false and it worked for me

在 GitHub Actions 的工作流文件中(可能是 main.yml),添加 CI: false。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接