#Module not found: Can't resolve 'dns'
5 messages · Page 1 of 1 (latest)
It looks like you’re importing/server code into a browser/client component. The error “Module not found: Can’t resolve 'dns'” comes from Node.js built-ins (dns, dgram, fs, etc.) being pulled into a browser bundle via pg → @prisma/adapter-pg. That adapter (and Prisma Client “server” runtime) must only run on the server. [adapter-pg issue]
What to do:
-
Ensure all Prisma usage (PrismaClient, @prisma/adapter-pg, pg) runs only on the server. Do not import them from React client components or any code that the browser bundles. If you need types in the browser, import from the generated “browser” entry, not “client.” [adapter-pg issue]
-
In a monorepo, avoid re-exporting server-only Prisma modules from a shared package that’s consumed by client components. Split exports:
- Server-only file (e.g., db.server.ts) that imports from generated prisma client and @prisma/adapter-pg.
- Client-only/types file (e.g., db.browser.ts) that imports only browser-safe types/exports from the generated “browser” bundle (not the Node client). [adapter-pg issue]
-
In Next.js/React:
- Keep Prisma code in server routes, server components, API routes, or server actions.
- If IDE auto-imports from generated “client” in a client component, change it to “browser” or remove the import. [adapter-pg issue]
Why this happens: bundlers for the browser cannot resolve Node built-ins like dns/dgram, but pg/@prisma/adapter-pg depend on them. Pulling those into client bundles triggers these errors. [adapter-pg issue]
If you recently upgraded Prisma and started seeing this, it’s still the same root cause: a client-side import path accidentally pulls server runtime. Users in the linked issue fixed it by correcting imports (use “browser” for fronte
nd, “client” for server). [adapter-pg issue]
If you share more about where you import your db package in the files from the import trace, I can point to the exact import to move server-side.
I have not imported any types in my project
🤔 Alright, thanks for letting us know that there's still some help needed. A team member will reply to you shortly.
In the meantime, please let us know any additional info, questions, or which parts of the answer may need clarification.