91

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?

Dick Lucas
  • 12,289
  • 14
  • 49
  • 76

11 Answers11

132

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/

Rohit Nishad
  • 2,570
  • 2
  • 22
  • 32
aldobsom
  • 2,341
  • 1
  • 13
  • 13
  • 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 cannot – nonopolarity Feb 08 '21 at 16:33
  • Thank you, this helped – hot_penguin Apr 15 '21 at 16:49
  • 8
    i wonder why they treat warning as error, what is the purpose of differentiating "Error" and "Warning" at the first place tho? – rickvian May 31 '21 at 04:40
  • 1
    @rickvian [The intention is so that developers should not ship potentially broken configurations](https://answers.netlify.com/t/new-ci-true-build-configuration-treating-warnings-as-errors-because-process-env-ci-true/14434). – Vicktor Sep 23 '22 at 07:08
  • This command is helpful. I am able to ignore my temporary errors – Md. Maruf Sarker Mar 03 '23 at 18:56
  • 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 flag – Artem Ptushkin Mar 20 '23 at 10:19
60

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.

General Grievance
  • 4,555
  • 31
  • 31
  • 45
kk651
  • 690
  • 6
  • 7
21

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.

Dick Lucas
  • 12,289
  • 14
  • 49
  • 76
8

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.

nonopolarity
  • 146,324
  • 131
  • 460
  • 740
5

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

Danielle Cohen
  • 629
  • 8
  • 5
3

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

H3AR7B3A7
  • 4,366
  • 2
  • 14
  • 37
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

Varid Vaya
  • 194
  • 1
  • 15
1

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.

Dharman
  • 30,962
  • 25
  • 85
  • 135
theshubhagrwl
  • 743
  • 9
  • 17
1

CI='' npm run build

For more details please check this out HERE

0

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
...
jQN
  • 459
  • 6
  • 5
-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

kaizen
  • 1,132
  • 1
  • 14
  • 20