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.
./app/page.tsx
Module not found: Can't resolve './components/Button'
https://nextjs.org/docs/messages/module-not-foundCommon 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
- Read the importing file and request in the error.
- Run
git ls-filesto see the committed casing of the file. - Correct the import so the path matches the committed name exactly.
# 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.
npm install <package> # not --save-dev for runtime imports
npm ciHow 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.