Module not found: Can't resolve './lib/db'

The file name are correct and matching the case. working on local machine but giving error in vercel.

Module not found: Can’t resolve ‘./lib/db’

./lib/db.ts

import { PrismaClient } from “@prisma/client/”
declare global {
var prisma: PrismaClient | undefined
}
const prisma = global.prisma || new PrismaClient({ log: [“info”] });
if (process.env.NODE_ENV !== “production”) global.prisma = prisma;

/home/page.tsx

import prisma from ‘./lib/db’

const newUser = await prisma.user.create({
data: {
userId: id as string,
firstName: first_name,
lastName: last_name,
email: email_address,
},

Deployment URL or Custom Domain: deployment url
Environment (local, preview, production): production
Project Framework: nextjs
Build Settings:
  Framework Preset: yes
  Build Command (if not default):
  Output Directory (if not default):
  Install Command (if not default):
Node/Runtime Version:
Package Manager:
Relevant Packages:

Hi, @bishwaroopb-gmailcom! Welcome to the Vercel Community :smile:

We had a similar question crop up the other day, could you have a look at the solution I outlined there?

Let us know how you get on!

Hi Pawlean, Thanks for the help… But it seems doesn’t work for me… I check the file names and cases, all are correct. Attached the screenshot of my folder structure. While calling the function checkuser (present under lib folder, checkuser.ts
import file
) from the file route.ts under api (highlighted in yellow), giving the error.
folder structure

Did you find a solution? I have tried everything and double checked all. Previously successful deployments are also bringing up these same errors when redeploying. Help

Doesn’t work. Previous production versions that were built successfully are failing with the module not found errors on vercel. No change in code. I even installed a fresh version of nextjs with no modifications and deployed to a preview branch and the build still failed with module not found for all files.

Hi, @bishwaroopb-gmailcom!

Thanks for being patient with us :pray:

Are you still having issues? Might be worth clearing your Next.js cache:

  1. Stop your development server
  2. Delete the .next folder in your project root
  3. Run npm run dev or yarn dev to start the server again

Hey, @ninsau! Sorry to hear that you are having issues. It sounds like you’ve done all the right steps.

Could you provide a minimal reproducible example for us to dig further?

I have found a solution.

My npm install setup has always included --force without any problems. But for some reason, that was now breaking the application and causing module not found errors only on Vercel.

I took off the force flag and the errors disappeared.

I still don’t know why I was getting a module not found error even though that had nothing to do with npm install --force

1 Like

Thank you for coming back with your solution, @ninsau! :pray:

I’d be curious, @bishwaroopb-gmailcom - does that happen to work for you too?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.