Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

A build that passes locally fails on Netlify because of warnings

ErrorThe build passes with npm run build on your machine and fails on Netlify

Short answer

Netlify sets CI=true for every build. Some tools, Create React App among them, then treat warnings as errors. Put CI='' in front of the build command, in the Netlify UI or netlify.toml. Do not use CI=false: many tools read any non-empty string as true. Then fix the warnings.

  • Applies to Netlify build image, Node.js 22, npm 10
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Reproduce the Netlify condition locally by setting CI the way Netlify does. If the build now fails, the warnings are the cause.

    CI=true npm run build
  2. 2Match what you see, then jump to its fix

    1. 1Fails only on Netlify; the same build passes locally; CI=true npm run build failsNetlify sets CI=true and your tool fails on warningsFix
    2. 2You changed the build command in the UI and nothing changedThe command in the Netlify UI is ignored because netlify.toml sets oneFix

What does the error look like?

  • The build passes with npm run build on your machine and fails on Netlify
  • The log shows warnings, and the build stops on them

Cause 1 of 2

Netlify sets CI=true and your tool fails on warnings

1Check

Netlify sets CI=true as a convention for automated builds, and some libraries then change behaviour, including treating warnings as errors. Compare your local run with CI set and unset.

npm run build
CI=true npm run build

2Fix

Override CI at the start of the build command with an empty string. Do not use CI=false; values are strings and many libraries treat any non-empty value as true.

# netlify.toml
[build]
  command = "CI='' npm run build"
  publish = "build"

3Verify

Push, and watch the deploy log pass the build step.

git commit --allow-empty -m "retry netlify build" && git push

Confirmed by docs.netlify.com

Did this fix it?

Cause 2 of 2

The command in the Netlify UI is ignored because netlify.toml sets one

1Check

When a value is set in both netlify.toml and the UI, the file wins. Look for a command key in the file.

grep -n -A3 "\[build\]" netlify.toml

2Fix

Edit the command in netlify.toml, or remove the key there and keep it in the UI. To apply the override only to one deploy context, use a context block.

[context.production]
  command = "CI='' npm run build"

3Verify

Open the deploy log and read the first lines; the build command shown is the one you set.

netlify build

Confirmed by docs.netlify.com

Did this fix it?

How do I stop it coming back?

  • Run CI=true npm run build before you push, so you see what Netlify sees.
  • Treat the warnings as work to do: overriding CI only hides them.
  • Keep the build command in one place, netlify.toml, and not in both the file and the UI.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Web apps

tsconfig rejects allowImportingTsExtensions

An error that allowImportingTsExtensions needs noEmit or emitDeclarationOnly

allowImportingTsExtensions lets files import each other with .ts or .tsx extensions, and TypeScript only allows it together with noEmit or emitDeclarationOnly.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.