July 24, 2025
Fixing "Cannot Find Module" on Vercel
When deploying your Node.js or Next.js project to Vercel, you may encounter the error: This usually...
.png&w=3840&q=75)
When deploying your Node.js or Next.js project to Vercel, you may encounter the error:
Error: Cannot find module 'your-module-name'
This usually means that Vercel couldn't resolve a module you used in your code. This article covers the common causes and how to fix them.
If you're using a third-party package (like axios, lodash, etc.), make sure it's installed in your project:
npm install your-module-name
or
yarn add your-module-name
The module must be listed under dependencies, not just devDependencies, especially if it's used in server-side code:
"dependencies": {
"your-module-name": "^1.0.0"
}
Make sure your lockfile is committed to Git. Vercel uses this to install your exact dependencies. If the file is missing or outdated, it may not install the required modules correctly.
git add package-lock.json
git commit -m "Update lockfile"
git push
Go to your Vercel dashboard and trigger a redeploy to apply changes.
Vercel runs on a Linux-based file system, which is case-sensitive. This means:
import myModule from './Utils/MyModule';
will fail if the actual file is named ./utils/myModule.ts. Double-check your casing.
If you're using a monorepo or custom module resolution, make sure your tsconfig.json (or jsconfig.json) is correctly configured and that Vercel supports it.
To avoid issues, prefer relative paths over custom aliases unless necessary.
In your Vercel project settings, you can set a custom install command under the Build & Development Settings. Ensure it runs npm install or yarn install properly.
Some modules behave differently based on NODE_ENV. Ensure your environment variables are set correctly in the Vercel dashboard.
The "Cannot find module" error on Vercel is usually related to dependency installation, path resolution, or case sensitivity. By carefully checking these areas, you can ensure a smooth deployment.
If the error persists, consult Vercel logs for the full stack trace, or test your build locally using:
vercel build
to reproduce the issue before deploying.