Errors

Module Not Found

Learn why this error occurs and how to resolve it.

Why This Error Occurred

The module you're trying to import is not installed in your dependencies. When importing a module from npm, this module has to be installed locally.

For example, when importing the swr package:

// example.js
import useSWR from 'swr'

The swr module has to be installed using a package manager:

npm install swr
# or
yarn add swr
# or
pnpm add swr

If the module is a local file, make sure the import path is correct and the file actually exists in your project.

Possible Ways to Fix It

1. Install the missing dependency

Run the appropriate install command for your package manager to add the missing module to your package.json:

npm install <package-name>

2. Verify the file path

Make sure that the path you're importing refers to the right directory and file. Relative imports must start with ./ or ../:

// Correct — relative import
import { Button } from './components/Button'

// Also correct — absolute import (if configured)
import { Button } from '@/components/Button'

3. Check file casing

Make sure the casing of the file matches exactly. Some operating systems (like macOS) are case-insensitive by default, but production builds on Linux are case-sensitive — so an import that works locally may fail in production.

Example — this will fail on Linux if the actual file is MyComponent.tsx:

// ❌ Wrong casing
import { Thing } from './mycomponent'

// ✅ Correct casing
import { Thing } from './MyComponent'

4. Clear the module cache

Sometimes a stale cache can cause this error. Try clearing the cache and reinstalling:

rm -rf node_modules .next
npm install

5. Check for typos in the package name

Verify that the package name on npm matches what you typed. Common mistakes include:

  • @radix-ui/react-dialog vs @radix/react-dialog
  • framer-motion vs framer-motion-react
  • zustand vs zustandjs

Need more help? Check the official Next.js documentation or visit the GitHub Discussions.