fix(api-server): ignore Prisma generator output in dev watcher#1780
fix(api-server): ignore Prisma generator output in dev watcher#1780bellcoTech wants to merge 1 commit into
Conversation
The dev watcher already ignores the directory containing schema.prisma (api/db by default), but if a project configures the generator output to point outside that directory — e.g. output = "../src/lib/db/generated" — the watcher sees every regenerated file and schedules another rebuild, trapping the dev server in an infinite build loop. Resolves the generator output path from the Prisma config and appends it to chokidar's ignore list. When the output is undeclared or schema parsing fails, falls back to the existing behavior.
👷 Deploy request for cedarjs pending review.Visit the deploys page to approve it
|
|
@Tobbe Hit this during a 4.1 → 4.2 upgrade where my project still had the Fixed it for myself by moving the output to Just thought it'd be a nice safety net for anyone else upgrading from |
Greptile SummaryThis PR fixes an infinite rebuild loop in
Confidence Score: 5/5Safe to merge — the change is additive, falls back gracefully when the schema is unreadable, and mirrors the existing pattern used for Both changed files follow the established patterns in the codebase. The new No files require special attention. Important Files Changed
Reviews (2): Last reviewed commit: "fix(api-server): ignore Prisma generator..." | Re-trigger Greptile |
| * Resolves the absolute path the Prisma client generator writes to. | ||
| * Returns `undefined` if the schema or generator can't be read. | ||
| */ | ||
| export async function getPrismaGeneratorOutputPath(): Promise< | ||
| string | undefined | ||
| > { | ||
| try { | ||
| const prismaInternalsMod = await import('@prisma/internals') | ||
| const { getConfig } = prismaInternalsMod.default || prismaInternalsMod | ||
|
|
||
| const { schemas, schemaRootDir } = await getPrismaSchemas() | ||
| const config = await getConfig({ datamodel: schemas }) | ||
| const generator = | ||
| config.generators.find((entry) => entry.name === 'client') ?? | ||
| config.generators[0] | ||
| const output = generator?.output?.value | ||
|
|
||
| if (!output) { | ||
| return undefined | ||
| } | ||
|
|
||
| return path.isAbsolute(output) | ||
| ? output | ||
| : path.resolve(schemaRootDir, output) | ||
| } catch { | ||
| return undefined | ||
| } | ||
| } |
There was a problem hiding this comment.
Duplicated generator-path resolution logic
getPrismaGeneratorOutputPath performs the same @prisma/internals import, getPrismaSchemas() call, getConfig invocation, generator lookup, and path.resolve that already exists verbatim in resolveGeneratedPrismaClient (lines 196–222). If the resolution logic ever changes — e.g. different generator-name heuristics or a new schemaRootDir lookup — both functions will need the same update and it's easy to miss one. Consider refactoring resolveGeneratedPrismaClient to call getPrismaGeneratorOutputPath() and layer its extra ext / existence-checking logic on top.
There was a problem hiding this comment.
Looking at this now
There was a problem hiding this comment.
Agreed, but to combine needs to affect more internal code. This PR may not even go in - not worth rewriting a lot for a potential non-issue
|
| Command | Status | Duration | Result |
|---|---|---|---|
nx run-many -t test --minWorkers=1 --maxWorkers=4 |
❌ Failed | 3m 25s | View ↗ |
nx run-many -t build:pack --exclude create-ceda... |
✅ Succeeded | 2s | View ↗ |
nx run-many -t build |
✅ Succeeded | 2s | View ↗ |
nx run-many -t test:types |
✅ Succeeded | 11s | View ↗ |
☁️ Nx Cloud last updated this comment at 2026-05-14 13:57:07 UTC
7b30458 to
7d17ec9
Compare
|
I have a plan for related work here: https://github.com/cedarjs/cedar/blob/main/docs/implementation-plans/unified-prisma-db-module-plan.md So your reported issue is definitely something I want to fix :) |
|
Oh haha, Ok I was very unsure about this one but this makes more sense. I didn't see the doc. Happy to close and leave it with you if you'd like |
Leave it open for now. I'll take a closer look later and get back to you with how I want to handle this |

The dev watcher already ignores the directory containing schema.prisma (api/db by default), but if a project configures the generator output to point outside that directory — e.g. output = "../src/lib/db/generated" — the watcher sees every regenerated file and schedules another rebuild, trapping the dev server in an infinite build loop.
Resolves the generator output path from the Prisma config and appends it to chokidar's ignore list. When the output is undeclared or schema parsing fails, falls back to the existing behavior.