Back to Blog
Bug Fixes•2 min read

Fix 'Module not found: Can't resolve' in Next.js and Webpack

Scaleup Infotech Team
Scaleup Infotech Team

Custom Software & Business Automation

Next.jsWebpackTypeScriptImports

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:

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

bash
# Reinstall cleanly when node_modules is stale
rm -rf node_modules package-lock.json
npm install

Cause 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

Share this article:

Keep Reading

Ready to implement these ideas?

Discuss Your Project