"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:

Checklist

  1. Is it a package? (no ./ or @/) Install it:
    npm install framer-motion
    
    Then confirm it appears in package.json dependencies.
  2. Is it a shadcn/ui component? Add it:
    npx shadcn@latest add button
    
  3. Is it a local file? Check that the file exists at that exact path, including case: Button.tsx ≠ button.tsx.
  4. Using @/? Configure the alias in tsconfig.json:
    { "compilerOptions": { "paths": { "@/*": ["./src/*"] } } }
    
    For Vite, also set it in vite.config.ts:
    import path from 'path';
    import { defineConfig } from 'vite';
    export default defineConfig({ resolve: { alias: { '@': path.resolve(__dirname, './src') } } });
    
  5. 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 getServerSideProps in the Pages Router). Don't import it in a 'use client' component.
  6. 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.

Get the free "10 Prompts That Fix Broken AI Code" pack

Join the FixKit AI newsletter: one short email a week with real errors from Cursor, Lovable, Bolt & Replit users and how to fix them. Unsubscribe anytime.

Newsletter signup powered by beehiiv. We only use your email to send the newsletter.