Next.js "Module not found: Can't resolve" - Fix in CI
During next build the bundler could not resolve an import. The package is missing, a paths alias is not honored, or the file casing differs on the Linux runner.
What this error means
The build fails with Module not found: Can't resolve '<module>' referencing the importing file.
next
Failed to compile.
./app/page.tsx
Module not found: Can't resolve '@/components/Header'
https://nextjs.org/docs/messages/module-not-foundCommon causes
Missing dependency
The package is imported but not in package.json, or the lockfile install omitted it.
Alias or case mismatch
A tsconfig paths alias is wrong, or the filename case differs from the import on case-sensitive Linux.
How to fix it
Install the dependency and verify the path
- Install the package.
- Confirm the file exists with exact casing.
Terminal
npm install <package>
ls -la components/Header.tsxConfirm tsconfig path aliases
- Ensure baseUrl and paths map your alias to a real directory.
tsconfig.json
// tsconfig.json
{ "compilerOptions": { "baseUrl": ".", "paths": { "@/*": ["./*"] } } }How to prevent it
- Commit a lockfile and install with
npm ci. - Develop on a case-sensitive filesystem to catch casing bugs before CI.
Related guides
Next.js "Image Optimization requires" - Fix in CIFix Next.js image optimization errors in CI - a static export or unconfigured remote host means next/image ca…
Next.js ENOENT .next/build-manifest - Fix in CIFix "ENOENT .next/build-manifest.json" in CI - the build artifact is missing because the build did not run, w…
Next.js "Export encountered errors" - Fix in CIFix "Export encountered errors on following paths" in CI - a page threw during static export, often from runt…