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

Dav*_*mon 14 deployment continuous-integration travis-ci github-pages reactjs

我正在开发一个用于自学目的的反应天气应用程序。在 gh-pages 中部署相同。
URL
https://davisraimon.github.io/react-weather/
Repo
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
Run Code Online (Sandbox Code Playgroud)

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

env:
    process.env.CI : false
Run Code Online (Sandbox Code Playgroud)

仍然显示相同的错误。

任何人都可以帮助我摆脱这种情况吗...

Fra*_*mse 18

如果您必须从 GitLab CICD 管道中继续构建和部署,您可以包含 CI=false,如下所示:

CI=false npm run build
Run Code Online (Sandbox Code Playgroud)

或者

unset CI
npm run build
Run Code Online (Sandbox Code Playgroud)

这是一个完整的 gitlab_ci 作业示例:

build-dev:
  environment: DEV
  image: node:16
  stage: build
  script:
    - npm install
    - CI=false npm run build
  only:
    - /^devrelease-.*$/
  tags:
    - docker
Run Code Online (Sandbox Code Playgroud)

或者

build-dev:
  environment: DEV
  image: node:16
  stage: build
  script:
    - unset CI
    - npm install
    - npm run build
  only:
    - /^devrelease-.*$/
  tags:
    - docker
  
Run Code Online (Sandbox Code Playgroud)


END*_*ESA 14

  "scripts": {
    "start": "react-scripts start",
    "build": "CI=false && react-scripts build",  // Add CI=False here
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
Run Code Online (Sandbox Code Playgroud)


Bru*_*ins 11

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

  • 选择站点设置选项卡
  • 选择构建和部署
  • 向下滚动到环境变量并按编辑变量
  • 填写 Key = CI 和 Value = false
  • 按保存并触发新的部署

在此输入图像描述


小智 8

对我来说,解决方案是:

env: 
  CI: false
Run Code Online (Sandbox Code Playgroud)

  • 在哪里添加这一行? (8认同)

fig*_*lub 6

对我来说,更换npm run buildCI='' npm run build合作。