In this guide
A simple guide to this issue: 'Module not found: Can't resolve' in Next.js and Webpack. Learn why it happens, what to check first, and how to fix it.
It builds on your Mac but fails in CI, or it cannot find a module you can clearly see in the folder. 'Module not found' has a handful of distinct causes — let's rule them out one by one.
The Error
Module not found: Can't resolve '@/components/Button' (or './utils', or 'fs')
Cause 1: Path Alias Not Configured
If you use @/ imports, both TypeScript and the bundler must know what it maps to. Confirm your tsconfig.json:
{
"compilerOptions": {
"baseUrl": ".",
"paths": { "@/*": ["./*"] }
}
}Cause 2: Case-Sensitivity (Works Locally, Fails in CI)
macOS and Windows filesystems are case-insensitive; Linux (your CI/server) is not. import Button from "./button" resolves locally but fails on Linux if the file is Button.tsx. Make the import match the file's exact casing.
Cause 3: Dependency Not Installed
# Reinstall cleanly when node_modules is stale
rm -rf node_modules package-lock.json
npm installCause 4: Importing a Node Built-in on the Client
Trying to import fs, path, or crypto (Node modules) into client code fails because they do not exist in the browser. Move that logic into a Server Component, a Route Handler, or a server action.
Fast Triage
1) Does the path casing match exactly? 2) Is the alias in tsconfig? 3) Is it in package.json dependencies? 4) Is it a Node-only module used on the client? One of these four is always the answer.
Relevant Scaleup Infotech Services
Keep Reading
Fix React Search Results Showing the Wrong Data
Fix React search race conditions with request cleanup, cancellation, and stale-response checks. Includes code and a slow-network verification checklist.
5 min readFix Next.js Environment Variables Missing in Production
Fix missing Next.js production environment variables by checking build-time values, public prefixes, deployment settings, and the exact release artifact.
5 min readFix Laravel Queue Jobs Not Processing After Deployment
Recover Laravel queue jobs after deployment by checking the connection, queue name, workers, cached configuration, failed jobs, and restart behavior.
5 min read