Package not installed
- Check
npm ls <name>or look innode_modules/<name>- Fix
- Install it with
npm install <name>,yarn add <name>orpnpm add <name>
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.
"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.
Four quick questions, then a straight answer.
From your answers, this is quietly costing you traffic and nobody has the hours to chase it. Scaplet finds every affected page, drafts the fixes and tracks how AI answers mention you.
A data platform shipped 46 fixes without a ticket.
This looks handled. Re-check after a redesign, a migration or a big content push; that is when it breaks.
Your site is small and you have the time. Work through the steps on this page, starting with the pages that get the most traffic.
npm ls <name> or look in node_modules/<name>npm install <name>, yarn add <name> or pnpm add <name>find src -iname 'mycomponent*' and comparefs, dns or a package that depends on them?# 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// components/MyComponent.js exists
// Wrong on case-sensitive systems
import MyComponent from '../components/Mycomponent'
// Right
import MyComponent from '../components/MyComponent'// 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,
},
},
}// 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.
If the next thing you see is a runtime error in the browser console, see Uncaught ReferenceError is not defined.
Use the exact build command from CI, for example npm run build, so you test the same resolution rules.
Run the build in a Linux container or CI job if you develop on macOS or Windows, since casing errors only show there.
Confirm the package is in package.json and your lockfile, and that CI installs dependencies before building.
Resolution errors can hide each other. Fix the first named module, rebuild and read the next message.
4 questions people ask next, answered from the sources on this page.
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.
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.
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.
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 '...'.
Run the free audit, then approve the fixes. Every change can be undone.