Next.js "Module not found: Can't resolve" - Fix in CI
next build walked an import and could not find the target on disk or in node_modules. As with bare Webpack, the cause is a dependency that was never installed, a wrong or miscased path, or an alias Next was never told about.
What this error means
The build fails with Module not found: Can't resolve '<module>' and a Next.js "Import trace for requested module" block. It is deterministic - the same import fails the same way every run.
./app/dashboard/page.tsx
Module not found: Can't resolve '@/components/Chart'
https://nextjs.org/docs/messages/module-not-found
Import trace for requested module:
./app/dashboard/page.tsxCommon causes
Dependency not installed
The package is imported but missing from node_modules - not in package.json, or npm ci ran against a lockfile that omits it. Works locally where it was installed ad hoc.
Wrong path or case mismatch
A typo or wrong relative depth, or a casing difference. Linux runners are case-sensitive, so @/components/Chart vs a file named chart.tsx passes on macOS and fails in CI.
tsconfig path alias not picked up
A @/* alias declared in tsconfig.json/jsconfig.json paths resolves in the editor but not in the build when baseUrl/paths are missing or misconfigured.
How to fix it
Install the dependency and verify the path
Add the missing package and confirm the import resolves to a real file with exact casing.
npm install <package>
ls -la components/Chart.tsx # exact case must match the importDeclare the alias in tsconfig
Next.js reads baseUrl and paths from tsconfig/jsconfig - define them there, not in a separate Webpack config.
// tsconfig.json
{
"compilerOptions": {
"baseUrl": ".",
"paths": { "@/*": ["./*"] }
}
}How to prevent it
- Commit a lockfile and install with
npm cifor reproducible deps. - Match import casing to filenames; Next.js CI runs on case-sensitive Linux.
- Keep
baseUrl/pathsin tsconfig so aliases resolve in the build, not just the editor.