Fix My Error

Stuck? Solved.

Home › Fix Errors › JavaScript › Module not found
Module not found: Error: Can't resolve './Component'

Fix: Module not found

The most common build tool error in Webpack, Vite, and Node. Here are the 4 fixes, in order of likelihood.

Last updated: October 2026

⚡ The 30-second fix

Check these three things in order:

1. Does the file actually exist at the path you typed?
2. Is the package installed in node_modules?
3. Does the import path match how your build tool resolves paths?

90% of these errors are #1 or #2. The rest are path format issues.

What the error means

Your build tool (Webpack, Vite) or runtime (Node.js) tried to load a file or package you imported, and couldn't find it. The error usually names the exact path it failed on — that's your first clue.

// If you wrote:
import Button from './components/Button';

// The build tool looks for:
// ./components/Button.js
// ./components/Button.jsx
// ./components/Button.ts
// ./components/Button.tsx
// ./components/Button/index.js
// ...

// If none exist → Module not found

Four fixes, in order of likelihood

1

The file doesn't exist (most common)

Look at the exact path in the error. Open your file explorer. Does the file exist?

  • Wrong filename? (Button.jsx vs button.jsx)
  • Wrong folder? (./components vs ./Component)
  • Wrong case? macOS is case-insensitive; Linux is case-sensitive.
# Find the file
find . -name "Button*" -not -path "*/node_modules/*"

# If it doesn't exist — create it or fix the import
2

The package isn't installed

If the import is a package name (not ./ or ../), it must be in node_modules.

# Check if installed
ls node_modules/react-router-dom

# If missing, install it
npm install react-router-dom

# Or if it's a dev dependency
npm install -D typescript

# For monorepos, install in the correct workspace
npm install react-router-dom -w packages/web

Pro tip: If you recently cloned a repo, run npm install before anything else.

3

The path alias isn't configured

If you're using @/components/Button, your build tool needs to know what @ means. Check your config.

// ✅ tsconfig.json (or jsconfig.json)
{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@/*": ["src/*"]
    }
  }
}

// ✅ vite.config.js
import path from 'path';
export default {
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src')
    }
  }
}

// ✅ webpack.config.js
module.exports = {
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src')
    }
  }
}
4

Missing file extension in Node ESM

Node.js ESM (when "type": "module" is set in package.json) requires file extensions in relative imports.

// ❌ Fails in Node ESM
import { helper } from './utils';

// ✅ Works in Node ESM
import { helper } from './utils.js';

// Note: This only applies to Node.js, not Webpack or Vite
// Webpack/Vite resolve extensions automatically

🛡️ How to prevent it

Common variations

Error variation Most likely cause
Can't resolve './Component'File missing at relative path
Can't resolve 'react-router'Package not installed
Can't resolve '@/utils'Path alias not configured
Cannot find module './utils'Node ESM needs .js extension
ERR_MODULE_NOT_FOUNDNode.js specific — check package.json type

❓ Frequently asked questions

How do I fix Module not found error?

Check three things in order: does the file exist at the path you specified, is the package installed in node_modules, and is the import path correct for your build tool (relative vs alias vs package name). Most cases are one of these three.

Why does 'Can't resolve ./Component' fail but 'Can't resolve @/Component' work?

The @ symbol is a path alias configured in tsconfig.json or vite.config.js. If the alias isn't set up, only relative paths (./ or ../) or package names work. Check your build config for alias resolution.

How do I fix Module not found in Node.js?;

Run npm install to ensure the package exists. For local files, add the .js extension since Node.js ESM requires it. For CommonJS, check that the package.json 'type' field is set correctly.

Do I need the file extension in import statements?

It depends. Node.js ESM requires extensions. Webpack and Vite can resolve without extensions if the file is .js, .jsx, .ts, or .tsx. TypeScript configures this in tsconfig.json with moduleResolution.

Why does the error appear in production but not in development?

Case sensitivity. macOS and Windows file systems are case-insensitive (Component.js and component.js are the same file). Linux production servers are case-sensitive. The file that works locally won't resolve on the server.

🔗 Related fixes

← All Error Fixes