Short answer
Scroll up the build log to the first error, not the last line. Most often it’s a missing environment variable: Vite builds VITE_ variables into the code at build time, and Netlify doesn’t read .env files, so they must be set in the host’s settings. Next: a different Node version, a file name whose capital letters don’t match the import, or warnings treated as errors.
The four usual causes, and the fix
01
Environment variables missing at build time
Vite replaces VITE_ variables with their values when it builds, so they have to exist on the build machine. Netlify doesn’t read .env files during builds: add each variable in the site’s settings with the Builds scope. On Vercel, changed variables apply only to new deployments, so redeploy after adding them. Only put public values in VITE_ variables, since they end up in the browser.
02
A different Node version
The build machine uses its default Node version, which may not match yours. On Netlify, set a NODE_VERSION environment variable or add a .nvmrc file. On Vercel, set the Node.js version in the project’s build settings, or engines.node in package.json, which overrides the project setting.
// package.json (Vercel) "engines": { "node": "22.x" } # .nvmrc (Netlify) 2203
File name case doesn’t match the import
Mac and Windows treat Button.tsx and button.tsx as the same file; Netlify’s build machine doesn’t. An import that works on your laptop fails there, and Netlify warns the error may not say so. Match every import to the file’s exact name. To rename a file’s case, use git mv so Git records the change.
04
Warnings treated as errors, or peer dependency conflicts
Netlify sets CI=true, and some tools then fail the build on warnings. Netlify’s fix is to start the build command with CI='' (CI=false may not work). For "Could not resolve dependency" or "Conflicting peer dependency" errors, Netlify’s fix is an NPM_FLAGS environment variable set to --legacy-peer-deps. Also confirm the publish directory matches your build output folder (dist for a default Vite app).
Checked against the vendor’s docs on : Vite docs: Env variables and modes; Netlify docs: Environment variables; Netlify docs: Manage build dependencies (Node.js version); Netlify docs: Build troubleshooting tips; Vercel docs: Environment variables; Vercel docs: Node.js versions.
Rather hand it over?
Fixed scope, fixed price, paid upfront. The work happens in writing; no call needed.
- from $450App Fix TicketOne reproducible bug in an existing mobile or web app, diagnosed and fixed.See scope and start
- from $450AI-Built App RescueA Lovable, Bolt or Cursor app checked end to end in 3 days, then its worst problems fixed at a fixed price.No issues worth fixing, no charge. If the Launch Check finds nothing rated medium or higher, Simon refunds the full $450. You keep the report either way.See scope and start
Related: Page not found on refresh · Lovable, Bolt and Replit app fixes