Error fixes
Fix 'Module not found: Can't resolve' in Next.js
The bundler tried to follow an import and could not find a matching package or file, so the build stops. Check the exact string in the error against what is installed and what exists on disk, paying attention to filename case, extensions, path aliases and whether the import runs in the browser.
By CodingMarble · Published · 5 min read

The error text and how to read it
./src/components/Header.tsx
Module not found: Can't resolve 'lucide-react'
./src/app/page.tsx
Module not found: Can't resolve '@/components/Hero'
./node_modules/some-lib/index.js
Module not found: Can't resolve 'fs'The first line is the file that contains the import. The quoted string is the exact specifier the bundler tried to resolve. Resolution follows fixed rules: a bare name such as lucide-react is looked up in node_modules, walking up parent directories; a relative path such as ./Hero is looked up from the importing file; and an alias such as @/ is rewritten using your tsconfig or jsconfig paths before lookup. For each candidate the bundler also tries known extensions. If none of those locations yields a file, you get this error.
So the question to answer is always the same: given this exact string in this exact file, what would the bundler have to find, and does it exist? The causes below are ordered by how often they turn out to be the answer.
Cause 1: the package is not installed where the build runs
A bare specifier fails when the package is absent from node_modules. Typical reasons are that you copied code from a tutorial without installing its dependency, that the install was run on another machine and node_modules was not copied, or that the package is listed in package.json but the install did not complete. Check with the package manager rather than by eye.
# Is it resolvable from the project root?
node -e "console.log(require.resolve('lucide-react'))"
# Is it declared and installed?
npm ls lucide-react
# Install and record it in package.json
npm install lucide-reactOn a production server the more subtle version is dependencies versus devDependencies. If your deploy installs with the production-only flag, or the platform sets NODE_ENV to production before install, devDependencies are skipped. A package imported by application code, or a build-time tool such as the CSS or TypeScript tooling your framework needs during the build, must be available in the environment that runs the build. Check your host's documentation for whether the build step runs with devDependencies installed. Anything the running app imports belongs in dependencies.
Cause 2: wrong relative path, extension or filename case
A relative import fails if a folder level is missing, if a file was renamed, or if the extension is not one the bundler tries. TypeScript and Next.js resolve .ts, .tsx, .js, .jsx and .json by default for extensionless imports, but importing a file with an unusual extension, or a file in a directory without an index file, needs the explicit path.
Filename case is the classic reason a project builds on a Windows or macOS laptop and fails on a Linux server. Those default file systems are case-insensitive, so importing ./header finds Header.tsx locally. Linux file systems are case-sensitive, so the same import fails in the deploy. The error mentions the lowercase name you typed, and the file on disk has a capital letter. Fix the import to match the file exactly. Renaming a file only by changing its case can be silently ignored by git on a case-insensitive system, so use git mv or rename it through a temporary name, then confirm with git ls-files that the tracked name is the one you want.
# Show tracked paths that contain "header" in any case
git ls-files | grep -i header
# Rename with a case change safely
git mv src/components/header.tsx src/components/tmp-header.tsx
git mv src/components/tmp-header.tsx src/components/Header.tsxCause 3: a path alias that is not configured
Imports like @/components/Hero work only because a config file maps the @ prefix to a folder. In a TypeScript project that mapping lives in tsconfig.json under compilerOptions.paths, together with baseUrl where your Next.js version requires it. In a JavaScript project the same fields go in jsconfig.json. Next.js reads these files and teaches its bundler the alias. If the file is missing, the paths block is malformed, or the target folder is wrong, every aliased import fails at once, which is a useful clue: many errors that all start with the same prefix point at the alias, not at individual files.
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
}
}Make sure the alias target matches your real layout. If your components live in the project root rather than in src, then @/* must map to ./* instead. After editing tsconfig, restart the dev server, because the alias table is read at startup. Tools outside the bundler, such as a separate test runner or a Node script, need their own alias configuration and will not pick up the Next.js one.
Cause 4: Node built-ins such as fs in client code
Can't resolve 'fs', 'path', 'crypto', 'net' or 'child_process' means code that needs Node.js is being bundled for the browser. The browser has no file system module, so the bundler has nothing to point at. The usual path is that a Client Component, or a file imported by one, imports a helper that reads files or talks to a database. In the Next.js App Router, anything reachable from a file marked with the use client directive is bundled for the browser.
Move the Node-only work to a Server Component, a route handler or a server action, and pass the resulting data to the client part as props or as a fetch response. If one module mixes both, split it so the file-reading function lives in its own file and is imported only from server code. Some projects add a package that marks a module as server-only so an accidental client import fails with a clear message. For a library that genuinely offers a browser build, check its documentation for the browser entry point rather than adding fallbacks that silently stub the module out.
Stale caches, lockfiles, and keeping it from returning
If you have verified that the file exists and the alias is right, and the error still appears, clear what the tools remember. Delete the .next folder to drop Next.js build output and caches, then retry. If a package was added or moved, remove node_modules and reinstall from the lockfile with the clean-install command your package manager offers, which fails loudly if package.json and the lockfile disagree. A lockfile from a different package manager than the one your host uses is another quiet source of missing packages, so keep exactly one lockfile in the repository.
Practical tip: reproduce a Linux-only failure locally before fixing it. Run the production build in a clean clone of your repository, or inside a Linux container, so that case-sensitivity and missing-file problems surface on your machine and not during a deploy.
To confirm the fix, run the full production build rather than only the dev server, since the dev server resolves lazily and may not visit every route. Commit the lockfile with every dependency change. In your continuous integration or deploy script, build from a clean checkout so that something that only existed on your disk cannot hide a missing import. And when you rename files, search the whole project for the old name, including dynamic imports and test files, before committing.
Keep reading
- Web developmentHow to Speed Up a Next.js WebsiteMost slow Next.js sites are slow for ordinary reasons: oversized images, late-loading fonts, too much client-side JavaScript and uncached data. Fix those four in order, and measure with both Lighthouse and real-user data so you know the change helped.
- Error fixesFix npm ERESOLVE Unable to Resolve Dependency Treenpm ERESOLVE means two packages in your project ask for incompatible versions of a shared dependency, usually a peer dependency, and npm refuses to guess which one wins. Read the tree in the error to find the package that pins the old version, then upgrade or align it; use --legacy-peer-deps only when you understand what it skips.
- Error fixesFix Next.js Hydration Failed: Server HTML MismatchThis error means the HTML React rendered on the server is different from what React produced in the browser on its first render, so it cannot attach to the existing markup. Find the node that differs, make the first client render produce exactly what the server produced, and move anything browser-only or time-dependent into an effect that runs after mount.
- Hosting and planningNext.js Hosting: Managed Platforms vs Self-HostingManaged front-end platforms such as Vercel and Netlify remove most operational work in exchange for less control and usage-based billing, while a VPS or Node host gives you control and predictable cost but makes you responsible for everything underneath. Pick by project type and by who will be on call when something breaks, then confirm current features and pricing on each provider's own pages.
Need this built properly for your business?
CodingMarble is a remote studio in India that builds websites, apps and games on fixed packages with the scope written down before payment. Try the free tools we run, or start a project when you are ready.