"Module not found: Can't resolve": A 60-Second Checklist for AI-Generated Code
Quick answer: Fix "Module not found: Can't resolve" in Next.js, Vite, and React apps written by Cursor, Lovable, or Bolt with this quick checklist.
The error
Module not found: Can't resolve 'framer-motion'
Module not found: Can't resolve '@/components/ui/button'
In Vite: Failed to resolve import "x" from "src/App.tsx". Does the file exist?
Why it happens
AI tools often write imports for things that don't exist yet:
- A package was imported but never installed
- A file path is wrong, or the file was never created
- The path alias (
@/) isn't configured - Letter case doesn't match (works on macOS, fails on Linux/Vercel)
- A server-only Node module (
fs,path) is imported in client code
Checklist
- Is it a package? (no
./or@/) Install it:
Then confirm it appears innpm install framer-motionpackage.jsondependencies. - Is it a shadcn/ui component? Add it:
npx shadcn@latest add button - Is it a local file? Check that the file exists at that exact path, including case:
Button.tsx≠button.tsx. - Using
@/? Configure the alias intsconfig.json:
For Vite, also set it in{ "compilerOptions": { "paths": { "@/*": ["./src/*"] } } }vite.config.ts:import path from 'path'; import { defineConfig } from 'vite'; export default defineConfig({ resolve: { alias: { '@': path.resolve(__dirname, './src') } } }); - Can't resolve 'fs' / 'path'? Move that code into a server file (a Server Component, Route Handler, or Server Action in the App Router, or
getServerSidePropsin the Pages Router). Don't import it in a'use client'component. - Still failing? Do a clean reinstall:
rm -rf node_modules package-lock.json .next && npm install
Prompt to paste into your AI tool
List every import in this project that doesn't resolve to an installed package in package.json or an existing file. For each, either install the package or create/fix the file path.
FAQ
Works locally but fails on Vercel? It's almost always case sensitivity, or a package installed globally rather than in package.json.
Should I use --legacy-peer-deps? Only if the install fails on peer conflicts. It hides version mismatches.
Still stuck? Paste your exact error into the free Error Fixer to get a plain-English cause, the fix, and a prompt to paste back into your AI tool.