SvelteKit and generated output directory

Hi, I'm building a SvelteKit app and we need to add a generated output directory. After adding the output line in the schema and generating, I'm getting tons of errors like the following:
12:51:26 PM [vite] Error when evaluating SSR module /src/lib/server/db/documents.ts:
|- TypeError: __vite_ssr_import_3__.cwd is not a function
at C:\Users\Carter\Documents\GitHub\EMU\memo\src\lib\generated\prisma\client.ts:42:19
at async instantiateModule (file:///C:/Users/CarterCochran/Documents/GitHub/EMU/memo/node_modules/.pnpm/vite@5.4.19_@types+node@24._197072922108a960c156e28bf027ecb4/node_modules/vite/dist/node/chunks/dep-C6uTJdX2.js:53020:5)
12:51:26 PM [vite] Error when evaluating SSR module /src/lib/server/db/documents.ts:
|- TypeError: __vite_ssr_import_3__.cwd is not a function
at C:\Users\Carter\Documents\GitHub\EMU\memo\src\lib\generated\prisma\client.ts:42:19
at async instantiateModule (file:///C:/Users/CarterCochran/Documents/GitHub/EMU/memo/node_modules/.pnpm/vite@5.4.19_@types+node@24._197072922108a960c156e28bf027ecb4/node_modules/vite/dist/node/chunks/dep-C6uTJdX2.js:53020:5)
Any ideas?
2 Replies
Prisma AI Help
Prisma AI Help2mo ago
You chose to compile with the bot. One moment while I piece together your answer… This error is commonly encountered when using a custom output directory for the Prisma Client in SvelteKit projects, especially when the generated client is placed outside of node_modules. Vite (used by SvelteKit) can have trouble with the way Prisma Client is bundled, leading to issues like the one you’re seeing. Solution:
Move the generated Prisma Client output into a subdirectory of node_modules, such as ../node_modules/@prisma-app/client, and import from there. This approach is recommended and has resolved similar issues for others:
generator client {
provider = "prisma-client-js"
output = "../node_modules/@prisma-app/client"
}
generator client {
provider = "prisma-client-js"
output = "../node_modules/@prisma-app/client"
}
Then, in your code:
import { PrismaClient } from '@prisma-app/client';
import { PrismaClient } from '@prisma-app/client';
This works because Vite and some package managers treat node_modules imports differently, avoiding the bundling issues that occur with custom output directories outside node_modules. Several users and official responses confirm this as the most reliable workaround for SvelteKit + Prisma custom output setups Prisma Sveltekit Generated Client -> exports is not defined, Multiple Connections / Databases / Datasources, How do I use two schema.prisma files and avoid exports is not defined?. Note:
- Always add the generated output directory to your .gitignore. - If you use multiple clients, ensure each has a unique output path in node_modules. If you still encounter issues, ensure you’re not importing the client in code that runs on the client/browser side—Prisma Client must only be used server-side. If this does not resolve your issue, the knowledge sources do not provide a solution specific to the cwd is not a function error, but the above steps address the most common root cause in SvelteKit + Prisma setups. ✅ Great, thanks for letting us know that this solved your question!
WTLccochran
WTLccochranOP2mo ago
That doesn't work either. Also, in your documentation it says "In Prisma ORM 7, Prisma Client will no longer be generated in node_modules by default and will require an output path to be defined."

Did you find this page helpful?