# Module not found: Can't resolve './components/Header' in webpack and Next.js: how to fix it

> Module not found: Can't resolve './components/Header' means the bundler followed an import and found no file or package there. The usual causes: the file name's case differs from the import (fine on macOS and Windows, fatal on a Linux build server), a wrong relative path or a missing extension, a package that is not in package.json, an @/ alias the bundler does not know, and, for Can't resolve 'fs', Node-only code pulled into the browser bundle.

Source: https://livops.dev/en/guides/error-module-not-found-cant-resolve

By Livops team, the people who build and run Livops. Updated 1 December 2026.

What people search for, as webpack 5 prints it:

```text
Module not found: Error: Can't resolve './components/Header' in '/app/src'
```

The same in Next.js:

```text
Module not found: Can't resolve './components/Header'
```

And the variant for a Node.js module in the browser bundle:

```text
Module not found: Error: Can't resolve 'fs' in '/app/node_modules/some-lib'
```

This page explains what the bundler was looking for, lists the reasons it did not find it, most common first, gives the fix for each, and says where the error shows on Livops.

## What does the error mean?

The message is built in two parts. webpack's resolver, `enhanced-resolve`, reports `Can't resolve '<what was imported>' in '<folder it looked from>'`[4], and webpack puts `Module not found: ` in front of it[3]. So the quoted name is exactly what is written in your `import`, and the folder is where the importing file lives.

**Read the quoted name first:**

- **A path** starting with `./`, `../` or `/` is a file of yours. Look for it from the folder at the end of the message.
- **A bare name** such as `'swr'` or `'lodash'` is a package, looked for in `node_modules`.
- **`@/` or `~/`** is an alias, which only works if the bundler was told about it.
- **`'fs'`, `'path'`, `'crypto'`** are Node.js modules, which do not exist in the browser.

Next.js now builds with Turbopack by default and still offers webpack with `next build --webpack`[6]. Its page for this error lists four causes: a package not installed, a file in another folder, a file with different casing, and Node.js-only modules in code that also runs in the browser[5].

## Causes, most common first

### 1. The case of the file name differs

The file is `components/header.jsx`, the import says `./components/Header`. On macOS and Windows that resolves, because their usual file systems (APFS, HFS+, NTFS) are not case sensitive[9]. On Linux it does not. Next.js's docs: incorrect casing leads to build failures on case-sensitive environments like most Linux-based continuous integration[5]. That is why the error appears only after you push.

**Fix:** make the import and the file name match, letter for letter. If you want to rename the file, do it with Git, not in the editor. On a case-insensitive file system Git sets `core.ignoreCase`, and then treats `header.jsx` and `Header.jsx` as the same file and keeps the name it already knew[9], so a rename in Finder or Explorer may never reach the repository. Do not flip `core.ignoreCase` by hand: Git's docs say changing it can cause unexpected behavior[9].

First see what Git has. `git ls-files` lists the files in the index[11], with the case they were committed with:

```sh
git ls-files src/components | grep -i header
```

Then rename through a temporary name with `git mv`, which renames a file and records it[10]:

```sh
git mv src/components/header.jsx src/components/Header.tmp.jsx
git mv src/components/Header.tmp.jsx src/components/Header.jsx
git commit -m "Rename header.jsx to Header.jsx"
```

The same applies to folders: `Components/` and `components/` are two different folders on the build server.

### 2. The relative path, the extension or the index file is wrong

The file is somewhere else (`../components/Header` from a page one level deeper), or the import leaves out something the bundler does not add on its own.

- **Extensions.** webpack tries the extensions in `resolve.extensions`, by default `.js`, `.json` and `.wasm`[1]. A `.jsx`, `.ts` or `.tsx` file imported without its extension resolves only if the config adds it. Setting the list replaces the default, so keep it with `'...'`[1]:

  ```js
  // webpack.config.js
  resolve: {
    extensions: [".tsx", ".ts", ".jsx", "..."],
  },
  ```

- **Folders.** An import of a folder resolves to the file named in `resolve.mainFiles`, by default `index`[1]. `./components/Header` finds `./components/Header/index.js`, but not `./components/Header/Header.js`.
- **ES modules.** In `.mjs` files, and in `.js` files whose nearest `package.json` has `"type": "module"`, webpack requires the file extension and does not resolve folders to `index`; otherwise it fails with `Module not found`[2]. Write `./utils.js`, not `./utils`.

### 3. The package is not installed in the project

The import is `'swr'` and there is no `swr` in `node_modules`. When you import a package from npm, it has to be installed locally[5]:

```sh
npm install swr
git add package.json package-lock.json
git commit -m "Add swr"
```

It works on your machine but not on the server when the package is there by accident: installed globally, copied by hand, or left over from an older branch. A global install does not help a bundler. npm puts global packages in `{prefix}/lib/node_modules` on Unix, and its rule of thumb is to install locally what you `require()` and globally only what you run on the command line[8]. The server installs only what `package.json` and the lockfile list.

### 4. An `@/` alias the bundler does not know

`import Header from "@/components/Header"` works in the editor, because the editor reads `paths` from `tsconfig.json` or `jsconfig.json`. The bundler resolves it only if it knows the alias too.

- **Next.js** has built-in support for `paths` and `baseUrl` in `tsconfig.json` and `jsconfig.json`[6]. `create-next-app` sets up `@/*` by default[6]. If the alias still fails, check the mapping: each entry in `paths` is relative to `baseUrl`[6].

  ```json
  {
    "compilerOptions": {
      "baseUrl": "src/",
      "paths": {
        "@/components/*": ["components/*"]
      }
    }
  }
  ```

- **Plain webpack** does not read `tsconfig.json` unless you tell it to. Either define the alias in `resolve.alias`[1], or, from webpack 5.105.0, set `resolve.tsconfig: true`, which reads `baseUrl` and `paths` from `tsconfig.json` and replaces `tsconfig-paths-webpack-plugin`[1]:

  ```js
  // webpack.config.js
  const path = require("path");

  module.exports = {
    resolve: {
      alias: { "@": path.resolve(__dirname, "src") },
      // or, on webpack 5.105.0 and later:
      // tsconfig: true,
    },
  };
  ```

Also check that `tsconfig.json` or `jsconfig.json` is committed: an alias defined in a file the server never gets does not exist there.

### 5. Can't resolve 'fs': Node.js code in the browser bundle

`fs`, `path`, `crypto` and the other Node.js core modules exist on the server, not in the browser. webpack 5 no longer polyfills Node.js core modules automatically[1]. For a module webpack 4 used to polyfill, such as `path` or `crypto`, the error adds a `BREAKING CHANGE` note that suggests `resolve.fallback`; `fs` is not on that list[3], so for `fs` you get the bare message.

**Fix in Next.js:** keep the code on the server. Node.js-only modules work inside `getStaticProps`, `getStaticPaths` and `getServerSideProps`; a module that imports one and is used by a component that also runs in the browser breaks the build[5]. In the App Router, a file marked `'use client'` brings all of its imports into the client bundle[7], so read files in a Server Component and pass the data down as props. To make the mistake obvious, mark server-only files[7]:

```js
// lib/data.js
import "server-only";
import { readFile } from "fs/promises";
```

Importing that module into a Client Component is then a build-time error that names the problem[7].

**Fix in plain webpack**, when a library only touches `fs` in a code path the browser never runs, give it an empty module[1]:

```js
// webpack.config.js
resolve: {
  fallback: { fs: false },
},
```

For `path`, `crypto` and the rest, the note in the error names the polyfill package to install if you really need the module in the browser[3].

## How to confirm the fix locally

Reproduce the server: a fresh clone on a case-sensitive file system, a clean install, the build.

```sh
git clone <your repo> /tmp/check && cd /tmp/check
npm ci
npm run build
```

A fresh clone catches files that were never committed and packages that exist only in your `node_modules`. To catch case mistakes on macOS or Windows too, build on Linux in a container:

```sh
docker run --rm -v "$PWD":/app -w /app node:22 sh -c "npm ci && npm run build"
```

## On Livops

- **Where it shows.** The error stops the build, so the deploy fails as `build_failed`, and the previous version keeps running. Livops's docs put it plainly: run `npm run build` on your machine and it stops in the same place. The exception is cause 1: on macOS or Windows your build may pass, so use the container above. See [Build failed](https://livops.dev/en/docs/error-build).
- **Linux.** The build runs on Linux, so the case of every file and folder name matters, as in cause 1.
- **Uploaded folders.** When you deploy by uploading a folder, `node_modules` is dropped, so a package that exists only in your local `node_modules` does not arrive. It must be in `package.json`, as in cause 3.
- **The commands are yours to set.** Livops detects Next.js, Vite, Create React App, Vue CLI, Angular and others and fills in the install and build commands. Change them in **Settings → Install** and **Settings → Build**, or in `livops.json`, where `install` and `build` are applied on every deploy:

  ```json
  {
    "install": "npm ci",
    "build": "npm run build"
  }
  ```

- **Static or server.** A statically built site is free on Livops. A Next.js app that renders pages on the server is deployed as an **Application**, not a static site. See [No site found](https://livops.dev/en/docs/error-output).
- **The assistant.** Next to the failed build, the assistant's button reads the log and explains what happened and how to fix it.

If the error is Node.js's own `Error: Cannot find module` when the app starts, not the bundler's, see [Error: Cannot find module](https://livops.dev/en/guides/error-node-cannot-find-module). If a build of an old webpack project stops on `error:0308010C`, see [ERR_OSSL_EVP_UNSUPPORTED](https://livops.dev/en/guides/error-err-ossl-evp-unsupported). If the site builds and then a refreshed page gives 404, see [404 on page refresh](https://livops.dev/en/guides/error-spa-404-on-refresh).

## Questions

**Why does it build on my Mac but fail on the server?**

Almost always the case of a file name. macOS and Windows treat Header.jsx and header.jsx as the same file; Linux, where build servers run, does not. Next.js's own docs name incorrect casing as a cause of build failures on Linux-based CI.

**I renamed the file but the error stays. Why?**

On a case-insensitive disk Git treats header.jsx and Header.jsx as one file and keeps the name it already knew, so a rename that changes only the case may never reach the repository. Check with git ls-files and rename with git mv through a temporary name.

**My @/components import works in the editor. Why does the build not find it?**

The editor reads paths from tsconfig.json or jsconfig.json; the bundler may not. Next.js reads paths and baseUrl from those files itself. Plain webpack needs resolve.alias, or resolve.tsconfig from webpack 5.105.0.

**How do I fix Can't resolve 'fs'?**

Keep code that uses fs on the server. fs is a Node.js module and does not exist in the browser, and webpack 5 no longer adds browser versions of Node modules. In Next.js, read files in a Server Component or getStaticProps, and mark server-only files with import 'server-only'. If a library only touches fs optionally, resolve.fallback with fs set to false gives it an empty module.

**Why do I need the file extension in some imports?**

In .mjs files, and in .js files whose package.json says type module, webpack requires the full file name with its extension and does not look for index files in folders. Write ./utils.js, not ./utils.

**Should I install the missing package globally?**

No. The bundler looks in the project's node_modules, not in npm's global folder. npm's rule is to install locally what your code imports and globally only what you run on the command line. Install it in the project and commit package.json and the lockfile.

## Sources

1. [webpack — Resolve](https://webpack.js.org/configuration/resolve/). Checked 1 December 2026.
2. [webpack — Module (Rule.resolve.fullySpecified)](https://webpack.js.org/configuration/module/). Checked 1 December 2026.
3. [webpack source — lib/errors/ModuleNotFoundError.js](https://raw.githubusercontent.com/webpack/webpack/main/lib/errors/ModuleNotFoundError.js). Checked 1 December 2026.
4. [enhanced-resolve source — lib/Resolver.js](https://raw.githubusercontent.com/webpack/enhanced-resolve/main/lib/Resolver.js). Checked 1 December 2026.
5. [Next.js Docs — Module Not Found](https://nextjs.org/docs/messages/module-not-found). Checked 1 December 2026.
6. [Next.js Docs — Installation](https://nextjs.org/docs/app/getting-started/installation). Checked 1 December 2026.
7. [Next.js Docs — Server and Client Components](https://nextjs.org/docs/app/getting-started/server-and-client-components). Checked 1 December 2026.
8. [npm Docs — folders](https://docs.npmjs.com/cli/v11/configuring-npm/folders/). Checked 1 December 2026.
9. [Git source — Documentation/config/core.adoc (core.ignoreCase)](https://raw.githubusercontent.com/git/git/master/Documentation/config/core.adoc). Checked 1 December 2026.
10. [Git Docs — git-mv](https://git-scm.com/docs/git-mv). Checked 1 December 2026.
11. [Git Docs — git-ls-files](https://git-scm.com/docs/git-ls-files). Checked 1 December 2026.
