A build that passes locally fails on Netlify because of warnings
The build passes with npm run build on your machine and fails on NetlifyShort 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.
Fix it fast
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 build2Match what you see, then jump to its fix
What does the error look like?
The build passes with npm run build on your machine and fails on NetlifyThe 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 build2Fix
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 pushConfirmed by docs.netlify.com
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.toml2Fix
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 buildConfirmed by docs.netlify.com
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 fixWeb apps
Apollo Server rejects a request as a potential CSRF
HTTP 400 Bad Request from the GraphQL endpoint
Apollo Server's CSRF prevention is on by default.
3 causes, each with a fixWeb apps
React shows Attempted import error when importing a component or function
Attempted import error:
The build found the file but not the name you asked for.
2 causes, each with a fixWeb apps
AxiosError Network Error with code ERR_NETWORK in a React app
Network Error
ERR_NETWORK means the request produced no readable response.
4 causes, each with a fixWeb apps
Axios get works with a URL string but ignores the object passed as the second argument
The server log shows a GET with no query string
axios.get takes a URL and an optional config object.
3 causes, each with a fixWeb apps
Can't resolve '../axios' in a React project
Module not found: Error: Can't resolve '../axios'
A path that starts with ./ or ../ is a file path, not the axios package.
3 causes, each with a fix