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.
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.
npm install <package>
ls -la components/Header.tsxConfirm tsconfig path aliases
- Ensure baseUrl and paths map your alias to a real directory.
// 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.