fix(seed): route prisma db seed through pnpm run for cwd resolution #234
Reference in New Issue
Block a user
Delete Branch "fix/prisma-seed-cwd"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Follow-up fix on #233. The
prisma db seedcommand failed withCannot find module './seed.ts'because the seed command's path was resolved against the user's cwd (apps/portal-bff/) and doubled intoapps/portal-bff/apps/portal-bff/prisma/seed.ts.Root cause: Prisma CLI spawns the seed command with cwd = wherever the user invoked
prisma db seedfrom. The pathapps/portal-bff/prisma/seed.tsonly works if cwd is the workspace root, but the user's habit (matchingprisma migrate dev) is to run prisma commands fromapps/portal-bff/.Fix: indirect through
pnpm run.pnpm runfor a root-level script always sets cwd = workspace root regardless of where invoked from. The seed path then resolves predictably.What lands
package.json(root)db:seednpm script inscriptscarrying the ts-node invocation.prisma.seedbecomespnpm run db:seed— the indirection forces cwd = workspace root before ts-node resolves the seed path.That's it. Two-line diff.
Why
pnpm runindirection workspnpm exec prisma db seedfromapps/portal-bff/apps/portal-bff/package.json, readsprisma.seedapps/portal-bff/apps/portal-bff/(inherited)pnpm run db:seedapps/portal-bff/pnpm runresets cwd to the package's root (workspace root)apps/portal-bff/prisma/seed.tsThe same flow works if the user invokes from the workspace root —
pnpm runstill ends up at workspace root, idempotent.Test plan
cd apps/portal-bff && pnpm exec prisma db seed— should report[seed] test-tenant complete — created … Person + … User + … UserScope rows; …. NoMODULE_NOT_FOUND.pnpm exec prisma db seed) — same result.created 0 Person + 0 User + 0 UserScope rows.pnpm runindirection trick + the cwd table above.Notes for the reviewer
package.json#prisma(Prisma 7 migration toprisma.config.ts) is unchanged — not in this fix's scope.prisma/seed.ts) and forcing the user to run fromapps/portal-bff/. Thepnpm runapproach is cwd-invariant — more robust to where the user invokes from.db:seedscript is callable directly (pnpm db:seed) which is a small ergonomic bonus.