Skip to content
Latchkey

Next.js "Module not found: Can't resolve" in CI

webpack could not resolve an import while compiling. In CI this is most often a case-sensitive path that worked on macOS, a dependency in devDependencies that was pruned, or a path alias that is not configured for the build.

What this error means

next build fails with "Module not found: Can't resolve './Components/Button'" or a package name, naming the importing file and the request. It passes locally on macOS or Windows but fails on the Linux runner.

next build
./app/page.tsx
Module not found: Can't resolve './components/Button'

https://nextjs.org/docs/messages/module-not-found

Common causes

A case-mismatched path on a case-sensitive filesystem

macOS and Windows resolve ./Components/Button and ./components/Button interchangeably; the Linux CI filesystem is case-sensitive, so the import fails.

The dependency is missing or only in devDependencies

A runtime import resolves to a package that was never installed in CI, or that npm ci --omit=dev pruned before the build.

How to fix it

Match the import to the real file case

  1. Read the importing file and request in the error.
  2. Run git ls-files to see the committed casing of the file.
  3. Correct the import so the path matches the committed name exactly.
app/page.tsx
# the file is committed as components/Button.tsx
- import Button from './Components/Button'
+ import Button from './components/Button'

Install the package as a real dependency

Move runtime imports out of devDependencies and run a clean install so the build sees them.

Terminal
npm install <package>   # not --save-dev for runtime imports
npm ci

How to prevent it

  • Develop with case-sensitive imports or test a Linux build before merging.
  • Keep runtime imports in dependencies, not devDependencies.
  • Configure path aliases in both tsconfig.json paths and next.config if used.

Frequently asked questions

What causes ""Module not found: Can't resolve""?
macOS and Windows resolve ./Components/Button and ./components/Button interchangeably; the Linux CI filesystem is case-sensitive, so the import fails.
How do I fix "Module not found: Can't resolve"?
Match the import to the real file case

Related guides

References

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