P
Prisma5mo ago
lforst

Cannot read undefined of Enum

I am using Next.js with turbopack and I keep getting Error: Cannot read properties of undefined (reading 'BAR') when trying to access an enum as follows:
import { Foo } from '@/generated/prisma/default';

console.log(Foo.BAR);
import { Foo } from '@/generated/prisma/default';

console.log(Foo.BAR);
Is this a bug or am I doing something wrong?
5 Replies
Prisma AI Help
Prisma AI Help5mo ago
You opted for speed from this bot. Let's conjure up an answer right now! This error—Cannot read properties of undefined (reading 'BAR') when accessing an enum imported from Prisma in a Next.js app (especially with Turbopack)—is a known issue that has affected several users. The root cause is often related to how Prisma generates and exports enums, especially when used in frontend/browser code or with certain bundlers like Turbopack or Webpack. Key points from the knowledge sources: - If an enum is defined in your Prisma schema but not used in any model, Prisma may not export it in the generated client, leading to it being undefined when imported in the browser or frontend code. This is confirmed in this issue, where a user notes:
"I had an enum in prisma that was not used inside any model. I noticed prisma does not export it unless you do so, no matter how many times you generate etc."
- There are also known issues with module resolution and missing enum exports in the generated client, especially with Next.js and Turbopack. For example, this issue shows a Module not found: Can't resolve './enums.js' error, which is related to how enums are bundled and exported. - A workaround is to ensure your enum is referenced in at least one model in your Prisma schema. This forces Prisma to generate and export the enum properly, making it available for import in your frontend code source. - If you are using a recent Prisma version (6.x), there are improvements in how enums are exported, and you can import enums from dedicated files (e.g., import { Role } from '~/generated/prisma/enums') source. What you should do: 1. Make sure your enum is used in at least one model in your Prisma schema. 2. Regenerate your Prisma client (npx prisma generate). 3. Try importing the enum from the correct path, as per your Prisma version a nd output configuration. If you still encounter issues, it may be a bug or a limitation with the current Prisma/Next.js integration, especially with Turbopack. In that case, check for open issues or consider using the workaround of referencing the enum in a model. If you need more specific help, please provide your Prisma schema and the generated client structure.
Nurul
Nurul5mo ago
Hey! Did the bot answer help?
lforst
lforstOP5mo ago
ahhh sick yes nice
Prisma AI Help
Prisma AI Help5mo ago
✅ Great, thanks for letting us know that this solved your question!
Nurul
Nurul5mo ago
Thanks for confirming! 🙌

Did you find this page helpful?