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

27,079

Solution 1

  "scripts": {
    "start": "react-scripts start",
    "build": "CI=false && react-scripts build",  // Add CI=False here
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },

Solution 2

For me the solution was:

env: 
  CI: false

Solution 3

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

Solution 4

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

Solution 5

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
  
Share:
27,079

Related videos on Youtube

Davis Raimon
Author by

Davis Raimon

Updated on April 22, 2022

Comments

  • Davis Raimon
    Davis Raimon about 2 years

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

    • Davis Raimon
      Davis Raimon almost 4 years
      Yes....When i do that it will work perfectly. Thanks
  • Prince Kumar Sharma
    Prince Kumar Sharma over 2 years
    thank u very much
  • Arinzehills
    Arinzehills about 2 years
    thanks so much bro
  • Mayank jain
    Mayank jain about 2 years
    Worked like a charm. Thanks !
  • twknab
    twknab almost 2 years
    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