Free auditStart free
GuideError · Build errors

Module not found: Can't resolve

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 withChatGPTClaudePerplexityGoogleAI Mode
02Fix it on your stack

Fix each cause

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
// 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.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
// 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.

03How 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.

  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.

01Why 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.

02It 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.

03I 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.

04Do 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. 01Next.js: Module not foundnextjs.org · checked 2026-11-01
  2. 02webpack: Resolve (alias, extensions, fallback, modules)webpack.js.org · checked 2026-11-01
  3. 03webpack: To v5 from v4 (resolve.fallback.fs)webpack.js.org · checked 2026-11-01
  4. 04npm CLI: npm installdocs.npmjs.com · checked 2026-11-01
Free · 2 minutes

Tools point. Agencies advise. This one ships.

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

Free, no card60 secondsNobody will call you
  • 46 fixes shipped without a ticket Brightpipe
  • 0→7 ChatGPT citations in six weeks Paylane