58

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
> 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

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...

Davis Raimon
  • 591
  • 1
  • 4
  • 5
  • Yes....When i do that it will work perfectly. Thanks – Davis Raimon Jul 01 '20 at 07:26
  • 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`. – Code-Apprentice Mar 01 '23 at 18:17

15 Answers15

84
  "scripts": {
    "start": "react-scripts start",
    "build": "CI=false && react-scripts build",  // Add CI=False here
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
ENDEESA
  • 3,373
  • 2
  • 21
  • 17
30

For me the solution was:

env: 
  CI: false
Beegee Motus
  • 303
  • 3
  • 5
16

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
  
Francois Harmse
  • 197
  • 1
  • 5
10

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

Brunno Vodola Martins
  • 1,582
  • 2
  • 15
  • 17
9

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

fight_club
  • 327
  • 4
  • 13
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.

Taslim Oseni
  • 6,086
  • 10
  • 44
  • 69
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

navinrangar
  • 904
  • 10
  • 20
  • 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 ;P – twknab Jun 12 '22 at 22:22
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!

Radall
  • 394
  • 4
  • 17
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"
  }
dawid debinski
  • 392
  • 4
  • 6
1

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
borke
  • 21
  • 2
0

In my case I was trying to deploy react app to Azure Static web pages via GitHub repo The env: CI: false

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

ivlad
  • 13
  • 4
  • Could you pleas be more specific? Where in the yml file? – Ricardo Álvarez Aug 05 '22 at 01:49
  • 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 ) – ivlad Jan 10 '23 at 22:52
0

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

script:
- CI=false yarn run build
Rajaram Shelar
  • 7,537
  • 24
  • 66
  • 107
0

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

Melvin
  • 73
  • 5
0

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

  script: 
    - CI=false yarn build
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

Younes Charfaoui
  • 1,059
  • 3
  • 10
  • 20