Vercel and Netlify Build Errors on Cursor-Generated Projects
Your Cursor-generated project builds and runs perfectly locally with npm run dev, but deploying to Vercel or Netlify fails with build errors. The platform's build log shows module resolution failures, SSR compatibility errors, missing dependencies, or Next.js/Nuxt-specific issues that didn't appear during development.
Vercel and Netlify run production builds in a clean environment, which exposes issues hidden by your local development setup. Hot module replacement (HMR) and development-mode error recovery mask problems that surface in production builds. Additionally, these platforms have specific requirements for server-side rendering, API routes, and static generation that differ from local development servers.
Each failed deploy means another round of pushing a fix and waiting 1-3 minutes for the build to run, making the feedback loop painfully slow compared to local development.
Error Messages You Might See
Common Causes
- Dependencies in devDependencies instead of dependencies — Cursor installed packages as devDependencies that are needed at build time. Vercel/Netlify may not install devDependencies in production builds
- Server-side code using browser APIs — Cursor generated code that references window, document, or localStorage in components that run during SSR, causing ReferenceError on the server
- Missing build-time environment variables — Environment variables used during the build (like API URLs, public keys) aren't configured in the Vercel/Netlify dashboard
- Node.js version mismatch — The platform uses a different Node.js version than your local machine. Cursor may have used syntax or APIs from a newer Node version
- Dynamic imports not handled for static generation — Pages that use dynamic data are configured for static export but can't be pre-rendered without the data source
- Monorepo or workspace configuration issues — The platform can't find the correct root directory or build command in a monorepo setup
How to Fix It
- Check the build logs carefully — The exact error message and the file/line it points to are your best debugging tools. Most build failures have a specific, fixable cause in the logs
- Guard browser API usage — Wrap browser-only code in checks:
if (typeof window !== 'undefined') { /* browser code */ }or use Next.js dynamic imports with{ ssr: false } - Configure environment variables on the platform — Add all required env vars in the Vercel/Netlify dashboard. For build-time vars in Next.js, prefix with NEXT_PUBLIC_
- Pin the Node.js version — Add
"engines": { "node": ">=18" }to package.json, or set the NODE_VERSION environment variable on the platform - Run the production build locally first — Execute
npm run buildlocally to catch the same errors before deploying. This replicates what the platform does - Move build-time packages to dependencies — If a package is used during build or SSR, it must be in
dependencies, notdevDependencies
Real developers can help you.
You don't need to be technical. Just describe what's wrong and a verified developer will handle the rest.
Get HelpFrequently Asked Questions
Why does my app work with npm run dev but fail on Vercel?
npm run dev uses a development server with hot reloading that's more forgiving. The production build (npm run build) runs static analysis, tree shaking, and SSR that expose issues hidden in development. Always test with npm run build locally before deploying.
How do I fix 'window is not defined' on Vercel?
This happens when server-side rendering (SSR) tries to run browser-only code. Wrap browser API usage in if (typeof window !== 'undefined') checks, or use Next.js dynamic() with ssr: false for components that require the browser environment.