Cursor app Vercel build failed: fix the error that npm run dev never showed

By AI App Medic · Updated · Cursor · Vercel · TypeScript · Vite

Cursor (or any AI editor) will keep a Vite or Next.js app running with npm run dev while the code still has type errors, mismatched imports, or a package.json the production installer cannot satisfy. You push to GitHub, Vercel runs npm run build, and the deployment fails with Command "npm run build" exited with 1. That last line is only the exit code. The cause is printed above it.

Step 1: read the log from the first red line

  1. In Vercel, open the failed deployment and expand Build Logs.
  2. Find whether it died during Installing dependencies or during Running "npm run build".
  3. Scroll to the first error, not the last. Later lines are often knock-on damage.

Typical first lines and what they mean:

Step 2: reproduce it on your machine

In the project folder, use the same installer Vercel will use:

git status          # start from what you actually pushed
npm ci              # or pnpm i --frozen-lockfile / yarn install --frozen-lockfile
npx tsc -b          # or npx tsc --noEmit, if that is what the build script runs
npm run build

Look at the build script in package.json. The common Vite React template is:

"build": "tsc -b && vite build"

Next.js apps fail inside next build when types are wrong. Either way, you want that failure locally so you can edit and rerun in seconds.

If npm ci itself fails, commit a consistent lockfile and avoid mixing npm and pnpm in the same repo. If peer dependencies conflict, fix the versions Cursor added, rather than deleting the lockfile on every push.

Step 3: fix the usual TypeScript leftovers

AI edits often leave unused variables, a string where a number is required, a missing prop, or an import that was renamed in one file but not the other. Work from the first tsc error downward. Do not sprinkle any on everything unless you are intentionally loosening a type, and do not set typescript.ignoreBuildErrors in Next.js just to get a green deploy.

If the errors are Cannot find module '@/...' at build time, the path alias exists in tsconfig.json but the bundler does not know it. For Vite, a typical fix is:

npm install -D vite-tsconfig-paths
// vite.config.ts
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import tsconfigPaths from "vite-tsconfig-paths";

export default defineConfig({
  plugins: [react(), tsconfigPaths()],
});

For a casing mismatch, rename with Git so the case change is committed:

git mv src/components/Button.tsx src/components/Button.tmp
git mv src/components/Button.tmp src/components/button.tsx
# then make the import match the file on disk, exactly

Step 4: Node version, root directory, and env values

If the log mentions an engine mismatch or a package that needs a newer Node, set the version in Vercel (Project Settings > General > Node.js Version) and, to be explicit, in package.json:

"engines": { "node": "22.x" }

A .nvmrc or volta field helps locally. Match what you used in Cursor.

If the app is in a subdirectory, set Root Directory in Vercel to that folder. Vite's output is usually dist; Next.js should use the Next.js preset and must not be pointed at dist by mistake.

A build can succeed and the live site can still be blank if client environment variables were missing at build time. Vite only inlines names that start with VITE_. Next.js only inlines names that start with NEXT_PUBLIC_ for the browser. Add them in Vercel for Production (and Preview if you need them there), then redeploy. The Next.js env variables undefined on Vercel guide covers every cause of this, step by step. The same class of bug is described for Netlify in Bolt env variables on Netlify. Never put a secret in those public prefixes; see API keys in the Vite bundle.

A short order of attack

  1. First red line in the Vercel log.
  2. Same failure with npm ci and npm run build locally.
  3. Types, then import casing, then install or Node, then project root and output, then env values.
  4. Redeploy only after a clean local production build.

Monorepos deserve one extra look. If Cursor created the app in a subfolder, or you later added a landing page package, Vercel may be building the repo root and never seeing the Vite or Next app. Set Root Directory to the package that contains this package.json, and make sure the lockfile Vercel installs is the one next to that app (or a workspace lockfile the installer understands). A correct local build in that folder, followed by a deploy with the same root, clears a surprising number of "it works on my machine" failures.

Once the production URL is up, open a deep link and refresh it, and run a quick scan for leaked keys. A green Vercel build does not mean the app is safe, only that it compiled.

FAQ

Why does the app work in Cursor if TypeScript is wrong?

The dev server transpiles your code and does not run the same type check as the production build. The official Vite template's build script is often tsc -b && vite build, so one type error stops Vercel after Cursor has been running for hours.

Should I set ignoreBuildErrors or skip tsc to ship faster?

You can, and you will ship the same mistakes to production. Fix the errors, or run the type check in CI some other way. Skipping it is a last resort, not a fix.

The install step fails with ERESOLVE. Is that the same problem?

No. That is npm being unable to pick a dependency tree, often a peer dependency conflict an AI change introduced. Resolve or pin the packages, and commit a lockfile that npm ci can use.

Related guides