Skip to content
Latchkey

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.

next build output
./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.tsx

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

Terminal
npm install <package>
ls -la components/Chart.tsx   # exact case must match the import

Declare the alias in tsconfig

Next.js reads baseUrl and paths from tsconfig/jsconfig - define them there, not in a separate Webpack config.

tsconfig.json
// tsconfig.json
{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": { "@/*": ["./*"] }
  }
}

How to prevent it

  • Commit a lockfile and install with npm ci for reproducible deps.
  • Match import casing to filenames; Next.js CI runs on case-sensitive Linux.
  • Keep baseUrl/paths in tsconfig so aliases resolve in the build, not just the editor.

Frequently asked questions

What causes ""Can't resolve" (Next.js)"?
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.
How do I fix "Can't resolve" (Next.js)?
Add the missing package and confirm the import resolves to a real file with exact casing.

Related guides

References

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