Skip to content
Latchkey

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-found

Common 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

  1. Install the package.
  2. Confirm the file exists with exact casing.
Terminal
npm install <package>
ls -la components/Header.tsx

Confirm tsconfig path aliases

  1. 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.

Frequently asked questions

What causes ""Can't resolve""?
The package is imported but not in package.json, or the lockfile install omitted it.
How do I fix "Can't resolve"?
Install the dependency and verify the path

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card