nvm use
npm install
npx prisma generate
npm run test
When instantiating Prisma in a test file
Error: PrismaClient is unable to be run in the browser.
In case this error is unexpected for you, please report it in https://github.com/prisma/prisma/issues
❯ new PrismaClient src/generated/client/index-browser.js:113:11
111| class PrismaClient {
112| constructor() {
113| throw new Error(
| ^
114| `PrismaClient is unable to be run in the browser.
115| In case this error is unexpected for you, please report it in https://github.com/prisma/prisma/issues`,
shows up.
(Credits to async
from the Vite-dev community Discord)
The problem is related with the Vite resolver. Two workarounds are:
- Add
resolver.alias
property tovitest.config.ts
:
resolve: {
alias: [
{
find: "<YOUR_CLIENT_PATH>",
replacement: resolve(__dirname, "<YOUR_CLIENT_PATH>/index.js"),
},
],
},
- Remove
browser
from the autogenerated Prisma clientpackage.json
.