Last modified: Jul 02, 2026
Fix Cannot Find Module '@prisma/client'
You are working on a Node.js project with Prisma. Suddenly, you see this error: Cannot find module '@prisma/client'. This is a common problem for beginners. It stops your app from running. But do not worry. This guide will help you fix it fast.
The error means Node.js cannot locate the Prisma client package. This package is essential for database queries. Without it, your app cannot talk to the database. Let us explore why this happens and how to solve it.
Why Does This Error Occur?
Prisma client is not a regular npm package. It is a generated client. You must run a command to create it. Many developers forget this step. They install Prisma but skip generating the client. This leads to the error.
Another reason is a missing node_modules folder. If you clone a project, you need to install dependencies first. Also, version mismatches can cause issues. For example, using an older Prisma version with a new client.
Sometimes, the error appears after updating Prisma. The old client does not match the new schema. You must regenerate it. Let us look at the solutions step by step.
Solution 1: Generate the Prisma Client
The most common fix is to generate the client. Open your terminal in the project root. Run this command:
npx prisma generate
This command creates the client based on your schema.prisma file. It places it inside node_modules/@prisma/client. After running it, the error should disappear. Try starting your app again.
If you use a custom output path, check your schema. The client might be in a different folder. Adjust your import path accordingly. For example:
// If you changed output in schema.prisma
const { PrismaClient } = require('./generated/client');
Solution 2: Install Dependencies
If you cloned a project from GitHub, you might lack dependencies. Run this command to install everything:
npm install
This installs all packages from package.json. It includes Prisma and other libraries. After installation, generate the client again. This ensures the client matches your schema.
Sometimes, the @prisma/client package is missing from package.json. Add it manually. Run:
npm install @prisma/client
Then regenerate the client. This is a reliable way to fix the error. For more help with module errors, check our guide on Fix Node.js Error: Cannot find module.
Solution 3: Clear Cache and Reinstall
A corrupted cache can cause this error. Clear the npm cache first:
npm cache clean --force
Then delete the node_modules folder and package-lock.json file. Reinstall everything:
rm -rf node_modules package-lock.json
npm install
npx prisma generate
This gives you a fresh start. It removes any broken packages. Many users find this solves stubborn errors. It is a good practice when other methods fail.
Solution 4: Check Prisma Version
Version mismatches are tricky. Your Prisma CLI version must match the client version. Check both versions:
npx prisma --version
npm list @prisma/client
If they differ, update them. Use the same version for both. For example:
npm install @prisma/client@latest
npm install prisma@latest
npx prisma generate
This ensures consistency. The client and CLI work together. If you still see issues, check the Prisma documentation. It has details on version compatibility.
Solution 5: Verify File Paths
Sometimes, the import path is wrong. In your code, you might import from a custom location. Ensure the path matches where the client is generated. The default import looks like this:
const { PrismaClient } = require('@prisma/client');
If you use ES modules, use import:
import { PrismaClient } from '@prisma/client';
Check your tsconfig.json or package.json for module settings. A wrong setting can break imports. For TypeScript, ensure esModuleInterop is true. This helps with default imports.
Solution 6: Run Prisma Migrate
If you changed your schema, you need to migrate. The client must stay in sync. Run:
npx prisma migrate dev
This applies changes to your database. It also regenerates the client automatically. If you prefer, you can run prisma generate separately after migration. This is a common workflow for schema changes.
Example: Full Fix Walkthrough
Let us walk through a real example. You have a Node.js app with Prisma. You see the error. Follow these steps:
First, check your project structure. Ensure you have a prisma/schema.prisma file. Then run:
npm install
npx prisma generate
Now, test your app. If the error persists, clear cache and reinstall:
npm cache clean --force
rm -rf node_modules package-lock.json
npm install
npx prisma generate
Finally, run your app again. You should see it work. Here is a sample output:
Server running on port 3000
Database connected successfully
This confirms the fix. The client is now found. Your app can query the database. For similar issues, read our article on Fix Node.js Error: Cannot find module.
Prevent This Error in the Future
To avoid this error, follow best practices. Always run npx prisma generate after schema changes. Add it to your build script in package.json. For example:
"scripts": {
"postinstall": "prisma generate",
"build": "prisma generate && node build.js"
}
This runs generation automatically. It saves you from forgetting. Also, keep Prisma versions consistent. Use package-lock.json to lock versions. This prevents accidental upgrades.
Another tip: use a CI/CD pipeline. Run prisma generate during deployment. This ensures the client is always up to date. It reduces errors in production.
Conclusion
The "Cannot find module '@prisma/client'" error is easy to fix. The main solution is to generate the client with npx prisma generate. If that fails, reinstall dependencies or clear the cache. Check version mismatches and file paths too. With these steps, you can resolve the issue quickly.
Remember to keep your Prisma setup organized. Use scripts to automate generation. This saves time and prevents future errors. Now you can focus on building your app. Happy coding!