ARTICLE AD BOX
I’m using Electron + Vue + Vite in a pnpm workspace, and I’m stuck between two Prisma import errors.
Environment
Electron 28.x
Prisma 5.22.0
@prisma/client 5.22.0
Vite + vite-plugin-electron
pnpm workspace on Windows'
The structure of the project
infrared_images_detector/ ├─ package.json ├─ pnpm-workspace.yaml ├─ vite.config.ts ├─ .env ├─ prisma/ │ └─ schema.prisma ├─ node_modules/ │ └─ .prisma/ │ └─ client/ │ └─ ... (generated runtime artifacts) ├─ electron/ │ └─ main/ │ ├─ index.ts │ ├─ generated/ # Prisma custom output target │ │ ├─ index.js │ │ ├─ index.d.ts │ │ └─ runtime/ │ ├─ prisma/ │ │ └─ client.ts # PrismaClient import switching point │ └─ services/ │ ├─ DatabaseService.ts │ ├─ FileService.ts │ └─ TaskService.ts └─ src/ └─ ... (renderer code)Prisma generator config (schema.prisma)
generator client { provider = "prisma-client-js" output = "../electron/main/generated/" }So Prisma Client is generated into a custom folder (generated) instead of the default client.
Case 1: import from @prisma/client
import { PrismaClient } from '@prisma/client'Then at runtime service initialization fails with:
服务初始化失败: Error: @prisma/client did not initialize yet. Please run "prisma generate" and try to import it again. at new PrismaClient (...node_modules\.prisma\client\default.js:43:11)Case 2: import from generated folder
import { PrismaClient } from '../generated'Then build fails with:
error during build: electron/main/prisma/client.ts (1:9): "PrismaClient" is not exported by "electron/main/generated/index.js", imported by "electron/main/prisma/client.ts"What I already tried
pnpm prisma generate
Switching import between @prisma/client and ../generated
Keeping schema output custom vs default (still confused which is correct in this Electron setup)
Question
What is the correct way to set this up with Electron + Vite?
If using custom generator output, how should I import PrismaClient so Rollup/Vite can build correctly?
If using @prisma/client, should I remove custom output and rely on default generation path only?
Are there known CommonJS/ESM interop issues with Prisma generated client under vite-plugin-electron?
Any minimal working pattern for this stack would be very helpful.
