Importing Prisma Client Models in Bun #14087
Unanswered
Pola-Malak
asked this question in
Q&A
Replies: 1 comment 1 reply
-
did you tried prisma generate? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi everyone!
I am new to Bun and experimenting with migrating an existing NestJS Backend node app to Bun. However, I’m encountering issues with importing models from Prisma Client while working with Bun v1.1.29.
Problem: Named imports throw errors, like:
import { User } from '@prisma/client';
throws something like this even thought it works with Node:
SyntaxError: Export named 'User' not found in module '/path/to/node_modules/@prisma/client/default.js'.
This issue arises when I try to import any other Prisma models as well. These imports work perfectly with Node.js but fail in Bun.
Code Example:
Here's an example userService.ts file that shows how I’m trying to import and use Prisma models in my project:
PrismaService.ts
Similarly:
import { Book,Author } from '@prisma/client'; // Throws error: 'Export named Book not found in module path/to/node_modules/@prisma/client/default.js '
This seems to relate to how Bun handles ESM and CommonJS modules. Bun doesn't recognize the named exports, although Prisma clearly exports them as types in the index.js file.
From the generated Prisma Client files, I can see the models are defined as types.
Setup:
Bun version: v1.1.29
Prisma version: v5.18.0
Node.js version: Works perfectly with Node 20.x
tsconfig.json used:
Questions:
How can I get Bun to handle named imports from Prisma Client properly?
Is there a specific tsconfig.json or Bun configuration I need for TypeScript compatibility?
Thank you for your help!
Beta Was this translation helpful? Give feedback.
All reactions