Error: Cannot find module / Module not found: Can't resolve in your AI-built app
Updated First published
On this page (4)
Symptom
The app won't start, the build fails or the page shows an error overlay, with a message like Error: Cannot find module 'express', Module not found: Can't resolve './components/Header', Failed to resolve import "@/lib/utils" from "src/App.tsx". Does the file exist?, or Cannot find module 'x' or its corresponding type declarations.
Cause
Every app is made of many pieces: your own files, and packages other people wrote, like React or the Supabase client. At the top of each file, the code says which pieces it needs, with lines like import ... from 'react'. When one of those pieces isn’t where the code expects it, you get this error.
The wording changes with the tool, but the meaning is the same:
- Node.js:
Error: Cannot find module 'express', orCannot find packagein newer projects. - Next.js:
Module not found: Can't resolve './components/Header'. - Vite (used by Lovable and many Bolt projects):
Failed to resolve import "@/lib/utils" from "src/App.tsx". Does the file exist? - TypeScript, in the editor:
Cannot find module 'x' or its corresponding type declarations.
It shows up in Cursor, Claude Code, Replit, and when you run a Bolt or Lovable project on your own computer.
Common causes
- The packages were never installed. A downloaded or cloned project doesn’t include the
node_modulesfolder. Runningnpm installcreates it from the list inpackage.json. - The package isn’t in package.json. The AI wrote an import for a package but never added it to the list, so
npm installdoesn’t know about it. - Wrong path or wrong capitals. The file is called
Header.tsxand the import says./components/header, or the file is in another folder. This often works on Mac and Windows and fails on Linux, which is where most hosting builds your app. - The @/ shortcut isn’t set up, or the file was never created. Imports like
@/components/ui/buttonneed the shortcut configured and the file to actually exist. The AI sometimes imports a component it never wrote. - The AI invented the package. It asked for a package with a believable name that doesn’t exist, or exists but is a copy made to trick people.
Beginner steps
- Read the name in quotes. Starts with
./,../or@/? It’s your file: go to step 5. A plain name? It’s a package: keep going. - Open a terminal in the right folder. It’s the one with
package.jsonin it. Runningnpm installanywhere else does nothing for this project. - Run
npm install. Wait for it to finish, then start the app again withnpm run dev. - Still missing? Check the package before you install it. Open
npmjs.com/package/followed by the exact name. If the page doesn’t exist, the AI invented it: don’t install anything with that name, and ask the AI what real package it meant. If the page exists, check that it has a description, a link to its code and recent versions, and that it does what the AI said. Then runnpm installfollowed by the name. - For your own files, open the folder the import points to and compare the file name letter by letter, capitals included. Or paste the prompt on this page and let the AI fix only that import.
- Restart the dev server after installing or renaming, with Ctrl+C and
npm run devagain. - Last resort: delete the
node_modulesfolder and runnpm installagain. Keeppackage.jsonand the lock file.
A fake package is a security problem, not just an error. If you think you installed one, uninstall it and follow How to keep API keys safe, because a harmful package can read keys stored on your computer. For a real case of a fake add-on in an editor, see Cursor’s fake Claude Code extension.
If npm install itself stops with an ERESOLVE error, see ERESOLVE unable to resolve dependency tree. If the app won’t start because the port is taken, see Port 3000 is already in use. If it builds but the page is empty, see My app shows a blank screen. If the AI keeps saying it’s fixed and the error comes back, read The AI says it fixed it, but the error is still there.
Prompt to paste
Copy the text below, replace what’s in brackets and send it in the chat of the tool you’re using.
My app shows this error:
[paste the whole error, including the file name and line number]
It happens when: [I run npm run dev / I run npm run build / I publish].
First, tell me whether the missing name is a file in my project or a package, without changing anything.
If it's a file: find the right path, checking capital and lowercase letters exactly, and fix only that import.
If it's a package: check that it's listed in package.json. If it isn't, tell me the exact package name and its page on npmjs.com, and explain what it's for, before installing anything. If you're not sure the package exists, say so instead of guessing.
Don't add other packages and don't rewrite unrelated code. Then tell me in one sentence what was wrong.How not to burn credits
- Run npm install yourself before you ask the AI. If the project was just downloaded or cloned, that alone usually fixes it.
- Send the whole error in one message. The name in quotes and the file it came from tell the AI exactly where to look.
- If the AI wants to install a package you've never heard of, ask for the npmjs.com link first and open it. That costs nothing and protects your computer.
- If the AI keeps swapping one missing package for another, stop. Go back to the last version that worked and ask for the feature again, saying which packages it may use.
How Lovable counts credits, and what the free plan includes: Lovable credits explained.
Questions people ask
What does Cannot find module mean?
Your code imports something by name, and Node.js or the dev server looked for it and found nothing. Next.js usually says Module not found: Can't resolve, Vite says Failed to resolve import and Node.js says Cannot find module. They all mean the same thing: a file or package the code needs isn't where the code expects it.
Is it a package or one of my files?
Look at the name in quotes. If it starts with ./ or ../, it's a file in your project, found from the file that imports it. If it starts with @/, it's usually a shortcut to your src folder, set up in tsconfig.json or the Vite config. Anything else, like react, zod or @supabase/supabase-js, is a package from npm.
I downloaded my project from Bolt or Lovable. Why doesn't it run?
Projects are shared without the node_modules folder, where the packages live, because it's large and can be rebuilt. Open a terminal in the folder that has package.json and run npm install once. If the folder has a pnpm-lock.yaml, yarn.lock or bun.lock file, use that tool's install command instead.
It works on my computer but fails when I publish. Why?
Often it's capital letters. macOS and Windows usually treat Header.tsx and header.tsx as the same file, but Linux doesn't, and most hosting builds your app on Linux. Make the import match the file name exactly. Another cause is a package that is installed on your computer but missing from package.json, so the hosting never installs it.
Can the AI invent a package that doesn't exist?
Yes. AI models sometimes suggest package names that sound right but don't exist, or that are slightly different from the real one. Attackers know this and publish harmful packages under those invented names, which is called slopsquatting. Before you install a package the AI suggested, open npmjs.com/package/ followed by its name and check that it has a description, a link to its code, a history of versions and real use.
Why is installing a fake package dangerous?
npm install can run scripts that come with the package, on your computer, as soon as it's installed. A harmful package can use that to read files or keys. That's why checking the name first matters more than the error itself. If you installed something suspicious, remove it with npm uninstall and read How to keep API keys safe.
Should I delete node_modules and reinstall?
Only if npm install didn't help. Delete the node_modules folder, keep package.json and the lock file, and run npm install again. This fixes packages that were only partly installed. It won't fix a package that's missing from package.json or a wrong path.
New guides by email. An email when we publish a new guide, error fix or chapter, in plain English. Subscribe