P
Prisma3w ago
hyteq

Monorepo package isn't generating client

It was working for a bit in my monorepo, but i changed nothing and now only in builds it says types cant be found, despite no type errors in development
1 Reply
Prisma AI Help
You chose to compile with the bot. One moment while I piece together your answer… Based on the knowledge sources, I can see that you're experiencing a common issue with Prisma Client generation in a monorepo setup. This is a known problem that many developers face, especially when using package managers like pnpm or yarn workspaces. Why this happens The issue occurs because in monorepos, Prisma Client generation can be tricky due to how package managers handle dependencies and node_modules. When Prisma generates the client, it might be placing it in a location that's not accessible to all packages, or the client might not be regenerated when needed during builds. Some specific causes might include: 1. Package managers like pnpm use symlinks and virtual stores which can confuse Prisma's client generation 2. The client might be generated in a package-specific node_modules folder rather than the root 3. Build caches (especially in CI environments) might not trigger regeneration of the client Solutions Here are some approaches that have worked for others: 1. Use a custom output path Configure your schema.prisma to use a custom output path:
generator client {
provider = "prisma-client-js"
output = "../path/to/custom/location"
}
generator client {
provider = "prisma-client-js"
output = "../path/to/custom/location"
}
Then re-export the client from a package that other packages can depend on Link to issue. 2. Add a postinstall script Add a postinstall script to your package.json to ensure the client is generated after installation:
"scripts": {
"postinstall": "prisma generate"
}
"scripts": {
"postinstall": "prisma generate"
}
This ensures the Prisma Client is generated whenever the @prisma/client package is installed Link to guidance. 3. For pnpm users If you're using pnpm, you might need to add the following to your .npmrc file:
strict-peer-dependencies=false
public-hoist-pattern[]=*prisma*
strict-peer-dependencies=false
public-hoist-pattern[]=*prisma*
This makes the prisma dependencies globally available to all workspaces in the monorepo [Link to issue](https://gith ub.com/prisma/prisma/issues/13672). 4. Manually regenerate the client Try running npx prisma generate explicitly before your build process to ensure the client is up to date. 5. Check for version conflicts Ensure you don't have conflicting versions of Prisma packages in different parts of your monorepo, as this can cause the issue you're experiencing Link to issue. If you're still facing issues, providing more details about your specific setup (package manager, monorepo structure, build process) would help in diagnosing the exact problem. I hope this helps! Let me know if you need more specific guidance based on your setup. ✅ Great, thanks for letting us know that this solved your question!

Did you find this page helpful?