DEV Community

Roby Cigar
Roby Cigar

Posted on • Updated on

Treating warnings as errors because process.env.CI = true.

This error happened everytime I deploy my react code to vercel. I solved this error by put this on scripts.
put this thing on your package.json, when you see

CI=false npm run build
Enter fullscreen mode Exit fullscreen mode

Don't put quotation as a string on env variable -vercel

scripts: {
  "build": "GENERATE_SOURCEMAP=false react-scripts build"
}
Enter fullscreen mode Exit fullscreen mode

There is also a built-in environment variable called NODE_ENV. You can read it from process.env.NODE_ENV. When you run npm start, it is always equal to 'development', when you run npm test it is always equal to 'test', and when you run npm run build to make a production bundle, it is always equal to 'production'. You cannot override NODE_ENV manually. This prevents developers from accidentally deploying a slow development build to production.

Top comments (6)

Collapse
 
kingagashi profile image
Rajarshi Agarwal

just go to settings -> environment variables ->and do the following
Name -> CI
Value -> False
and click Add


After this when u deploy, u wont get the problem again

Collapse
 
naziiriah profile image
`Nazir Abubakar

I don't completely understand what needs to be done to bypass this error.

Collapse
 
totorosyd profile image
Phoebe • Edited

agree with you. The author should give a bit more of context.

What he meant is that in your package.json, under "script" > "build". Whatever command build you have, you should add "CI = false" to override the default value which is "CI=TRUE".

For his example:
"build": "npm run build"
New line will be "build": "CI=false npm run build".

My case I have to write like this "build" : "CI=false && craco build". I used Typescript. Not sure if the && symbol needed or not. I dont bother to test actually :)

But if you only change in package.json and deploy vercel, Preview will be successful (Active) but Production still fails.
So, final solution to solve for both Preview and Production is to add environment variable in Project Settings > Environment Variables in Vercel.

Collapse
 
magimart profile image
Magima Felix O

you guys rock CI=false is the best fix
can also add it directly in vercel directly without adding it to a .env file of your project :)

Collapse
 
naziiriah profile image
`Nazir Abubakar

Thank you, for this.

Collapse
 
koulin profile image
Rafael Lima

You can create an env varaible on Vercel called CI and set it to false, that works too