How to prevent Netlify from treating warnings as errors because process.env.CI = true?
Asked Answered
Q

13

99

Deploying new projects started failing on Netlify. Checking the logs I see something that was not in the logs on previous successful deploys:

Treating warnings as errors because process.env.CI = true.
Most CI servers set it automatically. 
Failed to compile.

How can I fix my build?

Quiteri answered 16/6, 2020 at 19:3 Comment(1)
CI= npm run build The CI= yarn build doesn't seem to work for some reason.Let
C
140

You need to have CI to be false during your build command.

Go to: https://app.netlify.com/sites/mysales-krohne/settings/deploys > Build command and change it to:

CI=false npm run build

Now, rebuild your deployment. Should be no problem anymore.

If you want to know more about this. I wrote a blog on this topic: https://360techexplorer.com/treating-warnings-as-errors-because-process-env-ci-true-vercel-netlify-jenkins-etc/

Cattish answered 20/6, 2020 at 19:13 Comment(6)
wow... I wonder why they don't make it a default... or if our project can have some flag to toggle it... right now codesandbox.io can deploy my github project just by changing github to github box. Not Nelify and Vercel cannotLunitidal
Thank you, this helpedCatechize
i wonder why they treat warning as error, what is the purpose of differentiating "Error" and "Warning" at the first place tho?Burning
@Burning The intention is so that developers should not ship potentially broken configurations.Tropic
This command is helpful. I am able to ignore my temporary errorsAshelman
This should not be a solution tbh, if any other code depends on this env var then you make it inconsistent with the env - it will fail or have unexpected behaviour. I passed through all the comments and didn't find any proper solution... it should be a separate flagRecluse
C
63

Once your deployment is failed, go to Deploys -> Deployment Settings.

There you will see Environment tab. Then click Environment Variables -> Edit Variables

  • Key: CI
  • Value: False

Redeploy with clearing cache.

Cheiro answered 12/4, 2021 at 13:46 Comment(0)
Q
22

On June 15 2020 Netlify made a configuration change "adding the environment variable CI to build environments, with the value of true." In your Build and Deploy settings on Netlify change your build command to CI= npm run build. This will prevent Netlify from treating warnings as errors. More discussion on this issue can be found in Netlify's forums.

Quiteri answered 16/6, 2020 at 19:3 Comment(0)
L
10

Simply change the build command to:

CI= yarn build

or

CI= npm build

Like the other posts said, it is due to the CI, so any warning will stop the build. The lines above just means, setting the CI variable to nothing, and then start the command yarn build.

Lunitidal answered 9/2, 2021 at 2:36 Comment(0)
I
6

You should put CI='' npm run build in your build settings.

See error below: https://docs.netlify.com/configure-builds/troubleshooting-tips/#build-fails-on-warning-message

But its better to correct the warnings...

Inclined answered 27/7, 2020 at 15:32 Comment(0)
T
4

Go to Deployment settings then Environment Variable after that click Edit set key: CI value: false

In Build setting let it be only yarn build or npm run build as it is in default settings no need to add CI=yarn build or CI=npm build

Temporize answered 3/7, 2022 at 9:11 Comment(0)
L
2

Sometimes even after setting

CI = yarn build or npm build command

the build fails.

In my case, I ran the build command on my local machine and there was an error with an import which was not being displayed in netlify console.

So If the build is failing then run it once on your local machine this will notify of any errors.

Let answered 17/7, 2020 at 18:45 Comment(0)
E
2

CI='' npm run build

For more details please check this out HERE

Elba answered 10/11, 2020 at 14:2 Comment(0)
C
2

I found that everyone telling us to set the CI variable to false, but warning is something we should care about right? After all I see most of the CI servers implement such functionality, that I believe serve some purpose, maybe treating warnings as errors is just one of them. So instead of disabling such functionality, I think it's better to check whether you want to take these warnings in your deployed app or not. If it's something that you are expecting, for example lint warnings, then just configure your lint rules configuration or disable the lint checking on build phase, set it as separated step in the pipeline and you can set the CI variable to false on this specific stage. It feels safer than set the variable to false on the whole process if you are using for example azure static web apps deploy action

Concubinage answered 19/2, 2022 at 10:54 Comment(0)
K
2

In the pipeline add the line inside the script:

script:
          - npx browserslist@latest --update-db
          - npm i
          - npm ci
          - CI=false npm run build
Kink answered 28/2, 2024 at 10:14 Comment(0)
C
1

I was looking for a solution to fix this in Gitlab's CI and this is what worked for me in .gitlab.yml

...
default:
  before_script:
    - CI=false yarn build
...
Cultch answered 2/2, 2023 at 9:54 Comment(0)
A
0

Go to "Site configuration", under "Build & Deploy" section go to the "Continuous deployment" and configure the "Build settings" and change the "Build command" to "CI= yarn run build" or "CI= npm run build"

Note the space between CI= and the rest of the command

Arachnid answered 14/11, 2023 at 19:27 Comment(0)
L
-2

Redeploy again after deleting your site from netlify

Use the command npm run build and not yarn build

Don't try to rename your website name when deploy process is going on to avoid errors

Latoyalatoye answered 9/8, 2020 at 18:6 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.