# Module not found: Can't resolve

> Fix webpack and Next.js "Module not found: Can

Canonical: https://scaplet.com/errors/misc/module-not-found-can-t-resolve

Guide Error · Build errors

Fix webpack and Next.js "Module not found: Can't resolve": missing package, wrong path or casing, Node-only imports in browser code, extensions and aliases.

3 min

read

4

sources

Oct 30, 2026

updated

Scaplet Editorial Team

author

In one line

"Module not found: Can't resolve" means webpack (or Next.js, which uses it) could not find the file or package you imported. The documented causes are a dependency that is not installed, a path in the wrong directory, wrong file name casing, or a Node.js-only module imported in code that runs in the browser. Read the module name in the message, then check it against disk, `package.json` and the import path.

30-second check

## Where does your site stand?

Four quick questions, then a straight answer.

1/4Have you checked your own site for this?

Summarize this page with [ChatGPT](https://chatgpt.com/?hints=search&q=Summarize%20https%3A%2F%2Fscaplet.com%2Ferrors%2Fmisc%2Fmodule-not-found-can-t-resolve%20(%22Module%20not%20found%3A%20Can't%20resolve%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [Claude](https://claude.ai/new?q=Summarize%20https%3A%2F%2Fscaplet.com%2Ferrors%2Fmisc%2Fmodule-not-found-can-t-resolve%20(%22Module%20not%20found%3A%20Can't%20resolve%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [Perplexity](https://www.perplexity.ai/search?q=Summarize%20https%3A%2F%2Fscaplet.com%2Ferrors%2Fmisc%2Fmodule-not-found-can-t-resolve%20(%22Module%20not%20found%3A%20Can't%20resolve%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [![Google](/logos/ai/google-color.svg)AI Mode](https://www.google.com/search?udm=50&q=Summarize%20https%3A%2F%2Fscaplet.com%2Ferrors%2Fmisc%2Fmodule-not-found-can-t-resolve%20(%22Module%20not%20found%3A%20Can't%20resolve%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.)

On this page

## 3 parts, 3 minutes.

1. [Read the message, then pick the cause 01](#read-the-message-then-pick-the-cause)
2. [Fix each cause 02](#fix-each-cause)
3. [Confirm the fix 03](#confirm-the-fix)

_01_Causes from the Next.js docs, with a check for each

## Read the message, then pick the cause

The message names the [thing](/glossary/entity) webpack could not resolve and the file that imported it. Next.js's error page lists four reasons it happens, and each one has a fast check.

Cause

### Package not installed

Check

`npm ls <name>` or look in `node_modules/<name>`

Fix

Install it with `npm install <name>`, `yarn add <name>` or `pnpm add <name>`

Cause

### Module in a different directory

Check

Compare the import path with the folder tree

Fix

Correct the relative path or the alias

Cause

### Different casing

Check

`find src -iname 'mycomponent*'` and compare

Fix

Make the import match the file name exactly. Next.js says wrong casing breaks builds on case-sensitive environments like most Linux CI

Cause

### Node.js-only module in browser code

Check

Does the failing name look like `fs`, `dns` or a package that depends on them?

Fix

Move that code to server-only functions, or stub it in config

**Works on your Mac, fails in CI**Next.js says incorrect casing leads to build failures on case-sensitive environments like most Linux-based CI, so a case mismatch can hide on a machine that ignores case. An import of `../components/Mycomponent` for a file named `MyComponent.js` can pass locally and fail in the pipeline.

_02_Fix it on your stack

## Fix each cause

Missing package: confirm, install, rebuild
Missing package: confirm, install, rebuild

```
# Is it installed, and which version? npm ls swr # Install it npm install swr # or: yarn add swr / pnpm add swr # Clean reinstall if node_modules is stale rm -rf node_modules && npm install
```

Wrong casing: the import must match the file name
Wrong casing: the import must match the file name

```
// components/MyComponent.js exists // Wrong on case-sensitive systems import MyComponent from '../components/Mycomponent' // Right import MyComponent from '../components/MyComponent'
```

webpack: alias, extensions and fallback
webpack: alias, extensions and fallback

```
// webpack.config.js import path from 'node:path' import { fileURLToPath } from 'node:url' const __dirname = path.dirname(fileURLToPath(import.meta.url)) export default { resolve: { // Default is ['.js', '.json', '.wasm']; '...' keeps the defaults extensions: ['.ts', '.tsx', '...'], alias: { '@': path.resolve(__dirname, 'src'), }, // Redirect requests when normal resolving fails; // false means do not include a polyfill fallback: { fs: false, }, }, }
```

Next.js: keep Node-only code in server functions
Next.js: keep Node-only code in server functions

```
// pages/index.js import redis from '../lib/redis' // ioredis is Node-only export async function getStaticProps() { const message = await redis.get('message') return { props: { message } } } export default function Home({ message }) { return <h1>{message}</h1> }
```

Three details from the docs. `resolve.alias` takes precedence over other module resolutions. Setting `resolve.extensions` overrides the default array, so keep `'...'` if you still need `.js`. And Next.js notes its tree shaking of server-only imports only runs on top-level pages, so it cannot be relied on in separate React components, and a module that holds Node-only code should not also export React components.

_03_How it works

## Confirm the fix

If the next thing you see is a runtime error in the browser console, see [Uncaught ReferenceError is not defined](/errors/browser/uncaught-referenceerror-is-not-defined).

1. 01

### Re-run the same command that failed

Use the exact build command from CI, for example `npm run build`, so you test the same resolution rules.
2. 02

### Test on a case-sensitive file system

Run the build in a Linux container or CI job if you develop on macOS or Windows, since casing errors only show there.
3. 03

### Check lockfile and install step

Confirm the package is in `package.json` and your lockfile, and that CI installs dependencies before building.
4. 04

### Read the next error

Resolution errors can hide each other. Fix the first named module, rebuild and read the next message.

Questions

## Asked a lot.

4 questions people ask next, answered from the sources on this page.

_01_ Why does Can't resolve 'fs' appear in the browser build?

A module that uses Node.js APIs is being bundled for the browser. Next.js says to move such code into getStaticProps, getStaticPaths or getServerSideProps, which only run in Node.js. In webpack config, `resolve.fallback` with `fs: false` tells webpack not to include a polyfill.

_02_ It works locally but fails on the server. Why?

Often casing. Next.js documents that incorrect casing breaks builds on case-sensitive environments like most Linux-based CI. Make the import match the file name exactly.

_03_ I installed the package but it still fails. What now?

Check that it is in the right workspace folder and that the lockfile and node_modules match, then reinstall and rebuild. Also confirm the import path, since the module may live in a different directory.

_04_ Do I need resolve.extensions for TypeScript files?

If webpack must resolve `.ts` or `.tsx` imports without extensions, add them. The default is `.js`, `.json` and `.wasm`, and setting your own array overrides it unless you include `'...'`.

Sources · 4

## Every fact, linked and dated.

Official docs first. The date is when we last opened each page.

- nextjs.org
- js.org
- npmjs.com

1. 01 [Next.js: Module not found](https://nextjs.org/docs/messages/module-not-found) nextjs.org · checked 2026-11-01
2. 02 [webpack: Resolve (alias, extensions, fallback, modules)](https://webpack.js.org/configuration/resolve/) webpack.js.org · checked 2026-11-01
3. 03 [webpack: To v5 from v4 (resolve.fallback.fs)](https://webpack.js.org/migrate/5/) webpack.js.org · checked 2026-11-01
4. 04 [npm CLI: npm install](https://docs.npmjs.com/cli/v10/commands/npm-install) docs.npmjs.com · checked 2026-11-01

## Keep learning

[All errors](/errors)

[Learn Uncaught ReferenceError: x is not defined Browser errors](/errors/browser/uncaught-referenceerror-is-not-defined) [Related HTTP status codes Crawling and indexing](/glossary/http-status-codes) [Read next Uncaught TypeError: Cannot read properties of undefined Browser errors](/errors/browser/uncaught-typeerror-cannot-read-properties-of-undefined) [Do Run a free site audit Free, about two minutes](/site-audit)

Nearby in errors
[REST API status codes](/errors/http/rest-api-status-codes) [Access-Control-Allow-Origin](/errors/browser/access-control-allow-origin) [Aw, Snap!](/errors/browser/aw-snap)

More in Browser errors
[Cross-Origin Request Blocked](/errors/misc/cross-origin-request-blocked) [Module not found: Can't resolve](/errors/misc/module-not-found-can-t-resolve)

Terms on this page
[Entity](/glossary/entity)

Free · 2 minutes

## Tools point. Agencies advise. _This one ships._

Run the free audit, then approve the fixes. Every change can be undone.

[Audit my site free](/site-audit)

Free, no card 60 seconds Nobody will call you

- **46** fixes shipped without a ticket Brightpipe
- **0→7** ChatGPT citations in six weeks Paylane
