Open Ennoriel opened 4 months ago
SvelteKIT uses Vite which as far as i know doesn't support enums in client side code.
You have to use import type { UserStatus } from '@prisma/client';
@Eric-Arz can you link a vite issue or documentation section that supports this?
I am not trying to import the enum type but the enum itself.
Based on the error, I looked at .prisma/client/index-browser
and found it in the (probably bundled file) @prisma/client/index-browser.js
and replaced:
const prisma = require('.prisma/client/index-browser')
with
// relative path based on a pnpm install
const prisma = require('../../.prisma/client/index-browser')
rebuilt my project and it worked.
can you link a vite issue or documentation section that supports this?
Thanks for the linked issue!
The thing is that it's not really an enum, right?
Here is the generate .prisma/client/index.js
file generated with the schema of my issue:
exports.$Enums = {}
exports.Status = exports.$Enums.Status = {
fail: 'fail',
success: 'success'
};
Bug description
When importing an enum in the browser, it works in dev but fails with a production build with the following error in the browser console:
This issue is related to https://github.com/prisma/prisma/issues/16239 with a repro.
How to reproduce
git clone git@github.com:Ennoriel/bug-prisma-enum-browser.git cd bug-prisma-enum-browser npm i npx prisma generate npm run build npm run preview
Expected behavior
It should be possible to import and use the enums everywhere.
Prisma information
Environment & setup
Prisma Version