Skip to content

gdonoso94/vitest-prisma-integration-test

Repository files navigation

vitest-prisma-integration-test

nvm use
npm install
npx prisma generate
npm run test

Problem

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.

Solution

(Credits to async from the Vite-dev community Discord)

The problem is related with the Vite resolver. Two workarounds are:

  • Add resolver.alias property to vitest.config.ts:
resolve: {
    alias: [
      {
        find: "<YOUR_CLIENT_PATH>",
        replacement: resolve(__dirname, "<YOUR_CLIENT_PATH>/index.js"),
      },
    ],
  },
  • Remove browser from the autogenerated Prisma client package.json.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published