Treating warnings as errors because process.env.CI = true. Failed to compile
Asked Answered
S

16

67

I am working on a react-weather application for self learning purpose. Deployed the same in gh-pages.
URL
https://davisraimon.github.io/react-weather/
Repo
https://github.com/davisraimon/react-weather

When tried to integrate my application with Travis Ci, i got error as follows. It says like i have to change some env variable called 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
> [email protected] 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! [email protected] build: `react-scripts build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] 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

I added env variable in .travis.yml file.

env:
    process.env.CI : false

Still its showing the same error.

Can anyone help me out of this situation please...

Stradivari answered 30/6, 2020 at 17:57 Comment(2)
Yes....When i do that it will work perfectly. ThanksStradivari
For future readers process.env is the node variable that contains all environment variables. In the .travis.yml file, you should just use the variable name, in this case CI, without the process.env.Kreager
K
92
  "scripts": {
    "start": "react-scripts start",
    "build": "CI=false && react-scripts build",  // Add CI=False here
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
Keenan answered 15/3, 2021 at 7:10 Comment(2)
Didnt work, pipeline complaining > CI=false && react-scripts build 'CI' is not recognized as an internal or external command, operable program or batch file.Slipway
@Slipway was this on windows?Keenan
H
33

For me the solution was:

env: 
  CI: false
Hostetter answered 6/11, 2020 at 12:12 Comment(1)
Where to add this line?Hereafter
Z
18

if you have to continue with the build and deploy from within GitLab CICD pipelines, you can include CI=false like so:

CI=false npm run build

or

unset CI
npm run build

Here is a complete gitlab_ci job sample:

build-dev:
  environment: DEV
  image: node:16
  stage: build
  script:
    - npm install
    - CI=false npm run build
  only:
    - /^devrelease-.*$/
  tags:
    - docker

or

build-dev:
  environment: DEV
  image: node:16
  stage: build
  script:
    - unset CI
    - npm install
    - npm run build
  only:
    - /^devrelease-.*$/
  tags:
    - docker
  
Zorina answered 24/2, 2022 at 8:49 Comment(0)
A
11

In my specific case, I was using Netlify, so all I did was set the ENV vars inside Netlify's panel:

  • Select Site Settings Tab
  • Select Build and Deploy
  • Scroll down to Environment variables and press Edit Variables
  • Fill it in with Key = CI and Value = false
  • Press save and trigger a new deploy

enter image description here

Alviani answered 2/3, 2021 at 15:27 Comment(0)
H
9

For me replacing npm run build with CI='' npm run build worked.

Halfwitted answered 2/1, 2021 at 18:49 Comment(0)
N
5

Using Azure Static web pages via GitHub repo. Adding this worked like a charm:

env:
  CI: false

Just a quick note. This was applied to the yaml defining the CI process in GitHub actions. The env element has no indentation (at the same level as the name:)

Note: Given all is set the same way on your side, it should be located in your GitHub repo under the tab Actions -> Azure Static Web Apps CI/CD -> The link to the yaml is right under the title (Azure Static Web Apps CI/CD )

Azure static web-apps yaml:

enter image description here

Resource: https://github.com/Azure/static-web-apps/issues/179

Nautch answered 11/5, 2021 at 23:13 Comment(2)
Could you pleas be more specific? Where in the yml file?Boiardo
Given all is set the same way at your side it should be located in your github repo under tab Actions -> Azure Static Web Apps CI/CD -> the link to the yaml is right under the title (Azure Static Web Apps CI/CD )Nautch
N
2

Follow the steps below and your problem would be solved:

  • Select Site Settings Tab
  • Select Build and Deploy
  • Scroll down to Environment variables choose Edit Variables
  • Fill it in with Key = CI and Value = false
  • Press clear cache and redeploy

...and have fun.

Nightfall answered 17/7, 2021 at 10:53 Comment(0)
T
2

This happens due to your CI server setting (in my case it is netlify).. Follow the steps below and your problem would be solved:

Select--> Site Settings Tab

Select--> Build and Deploy

Scroll down to Environment variables choose Edit Variables

Fill it in with Key = CI and Value = false

Press clear cache and redeploy

Tymes answered 20/4, 2022 at 4:22 Comment(1)
Thank you for this -- after bashing awhile in this situation w/ Netlify, I caught on that the warnings were failing the build completely, then finally studied the output a bit more closely and saw mention of the flag...which the error output was a bit more robust. Thanks so much for helping unblock me ;PToothy
P
2

Coming from hours of googling, for me the following worked for Azure Devops:

In your package.json

"scripts": {
  ...
  "build": "set \"CI=false\" && react-scripts build"
}

Note: The escaped quotes are important!

Personality answered 27/7, 2022 at 9:8 Comment(0)
S
2

In case you want to deploy to a windows server or using powershell, you can set the environment variables like this:

script:
  - $env:CI="false"
  - npm run build

or:

$env:CI="false"; npm run build
Southing answered 31/8, 2022 at 6:9 Comment(0)
O
1

CI=true is needed in case you would like to process test during the deployment but it can be easily archived by setting a flag via package.json (in case in your dockerfile already set ENV CI=true you can remove it)

 "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "CI=true react-scripts test"
  }
Ophidian answered 9/8, 2021 at 11:46 Comment(0)
L
1

In Gitlab CI job in yml file, adding below script in my job worked for me.

script:
- CI=false yarn run build
Landgrabber answered 7/12, 2021 at 4:30 Comment(0)
L
0

you must fix the warnings you have in react, that's why it doesn't let you deploy

Linson answered 1/2, 2022 at 15:47 Comment(0)
R
0

I'm using gitlab ci & yarn and this worked for me:

  script: 
    - CI=false yarn build
Rebekahrebekkah answered 12/4, 2023 at 6:44 Comment(0)
B
0

For me, I was deploying a ReactJs project and I faced the CI error. I added an environment variable to Netlify. Variable name added was: CI and it's value was given as: false

Netlify then ignored the errors and performed the build.

Netlify add environment variable option:

enter image description here

Brookebrooker answered 5/6, 2023 at 20:35 Comment(0)
O
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

Add CI: false in the workflow file of github actions (main.yml probably)

Ozenfant answered 18/11, 2023 at 19:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.