Next.js · build error

Module not found: Can't resolve 'stripe' (package not installed)

verified on · Next.js 16.4.5 · React 19.3

Check yours: npm ls next react · On a different version? Paste your package.json into the free Doctor and it checks your versions against these fixes.

what it looks like
./src/lib/stripe.ts:1:1
Error: Module not found: Can't resolve 'stripe'
> 1 | import Stripe from "stripe";

https://nextjs.org/docs/messages/module-not-found

What it means

The name in quotes has no ./ and no @/ in front, so Next.js treats it as an npm package and looks for it in node_modules. It isn't there. This is an install problem, not a path problem. It often works on your laptop because you or the agent ran npm install there, but the build server only installs what is listed in the package.json and lock file you committed. Node scripts say the same thing as Cannot find module 'stripe' (or Cannot find package '@prisma/client' imported from ... for ES modules), and TypeScript says TS2307 Cannot find module 'stripe' or its corresponding type declarations. A name that starts with .prisma/client is different: @prisma/client is installed, but the client it generates into node_modules was never created because prisma generate didn't run.

Common causes

  • The agent wrote import Stripe from "stripe" but never installed the package, or installed it in a different folder (the repo root instead of the app folder in a monorepo)
  • It was installed on your machine but the updated package.json or package-lock.json was never committed, so the build server doesn't install it
  • It is in devDependencies and the build installs production dependencies only (npm ci --omit=dev, or NODE_ENV=production set before npm ci in a Dockerfile)
  • Can't resolve '.prisma/client/index-browser' or Cannot find module '.prisma/client/default': prisma generate never ran. The install skipped scripts (npm install --ignore-scripts, or pnpm 10, which doesn't run dependency install scripts unless you allow them) and the build script has no generate step
  • webpack sometimes adds Did you mean './stripe'? because you have a file called stripe.ts. Ignore that hint, the import really wants the npm package

How to fix it

  1. Read the name in quotes. No ./ and no @/ in front means it's an npm package. If it starts with @/ or ./ it's a path problem, see the Can't resolve '@/...' fix instead
  2. Install it in the folder that has your app's package.json, using the exact name from the error: npm install stripe (for a scoped name use the first two parts, like @prisma/client)
  3. Run git status. package.json and package-lock.json should show as changed. Commit both and push, or the build server still won't have the package
  4. If the build or the running app needs a package that sits in devDependencies, move it to dependencies, or don't set NODE_ENV=production before npm ci in your Dockerfile
  5. For .prisma/client or Module '@prisma/client' has no exported member 'PrismaClient' (TS2305), run npx prisma generate. Then make it automatic with "postinstall": "prisma generate" and a build script of prisma generate && next build
  6. Before you push, build a fresh clone the way the server does: git clone . /tmp/check, then npm ci and npm run build in it. A package that was never saved to package.json fails there first
terminal
# 1. Is it in package.json and installed?
grep '"stripe"' package.json
npm ls stripe

# 2. Install it where your app's package.json is, then commit both files
npm install stripe
git add package.json package-lock.json
git commit -m "Add stripe"

# 3. Prisma: .prisma/client means the client was never generated
npx prisma generate
#    package.json, so every install and build generates it:
#    "postinstall": "prisma generate",
#    "build": "prisma generate && next build"

# 4. Build what the server builds: a clean clone of what is committed
git clone . /tmp/check && cd /tmp/check && npm ci && npm run build

works with Next.js 16.4.5 · React 19.3last verified

Prompt for Cursor or Claude Code

My Next.js build fails with Module not found: Can't resolve '<package>' (or Cannot find module '<package>'). Check whether that package is listed in package.json and installed in node_modules in the folder where next build runs. If it's missing, install it there with npm install and remind me to commit package.json and package-lock.json. If it's only in devDependencies but the build or the app needs it, move it to dependencies. If the error mentions .prisma/client, run prisma generate and add "postinstall": "prisma generate" and a build script of "prisma generate && next build". Don't swap the import for a different package and don't change import paths. List every file you changed.

Not quite your error? Paste yours into the free VibeBoot Doctor or browse the Next.js error fixer.

Check your whole repo from the terminal: npx github:vibeboot/vibeboot-doctor (free, offline).

Upgrading from Next.js 15? The Next.js 16 upgrade checklist covers every breaking change, the error it causes and the fix.

next: skip the next one

Skip the setup. The VibeBoot SaaS Starter gives you auth, Stripe and a database already wired on Next.js 16, with AGENTS.md and .cursor/rules that keep your agent on the Next.js 16 conventions. $49, one-time.

14-day money-back guarantee · lifetime updates

$ fixed it? get the next one first

New fixes for what AI agents break, by email.

When we add a fix or a Cursor rule for a new Next.js, Auth.js, Prisma or Stripe break, it goes out in the VibeBoot newsletter. Free, occasional, unsubscribe in one click.

Subscribe free