fix(seed): use tsconfig.app.json instead of inline --compiler-options #235
Reference in New Issue
Block a user
Delete Branch "fix/prisma-seed-tsconfig"
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 to #234. The
db:seedscript's inline--compiler-options '{"module":"CommonJS",…}'was getting its quotes stripped by the shell whenpnpm runre-spawnedts-node:Cross-platform JSON-on-cmdline quoting through nested
package.json → shell → npm-script → shell → ts-nodeis a notorious pain.apps/portal-bff/tsconfig.app.jsonalready declares everythingts-nodeneeds to transpile the seed (module=commonjs, esModuleInterop=true, target=es2021, moduleResolution=node, types=[node]). Point at it with-Pand drop the inline JSON entirely.What lands
package.json(root)db:seedscript:--compiler-options '{...}'→-P apps/portal-bff/tsconfig.app.json. One-line diff.That's it.
Why
tsconfig.app.jsonworks for the seed even though seed.ts isn't undersrc/ts-node --transpile-onlyreadscompilerOptionsfrom the-Ptsconfig but ignores theinclude/excludefields for the file passed explicitly on the command line. So the fact thattsconfig.app.jsonhas"include": ["src/**/*.ts"]and the seed lives underprisma/doesn't matter —ts-nodehappily transpiles whatever file you point it at.Test plan
cd apps/portal-bff && pnpm exec prisma db seed— no moreSyntaxErroron the compiler-options, seed runs and reports[seed] test-tenant complete ….created 0 / 0 / 0.Notes for the reviewer
apps/portal-bff/prisma/tsconfig.jsonextending the app config. Less coupling but more files; pointing at the existingtsconfig.app.jsonis the minimum-surface fix.package.json#prismais unchanged; migrating toprisma.config.tsis a separate future PR (would also let us inline the seed config without shell quoting at all).The inline --compiler-options '{"module":"CommonJS",...}' was being unquoted by the shell when pnpm run db:seed re-spawned ts-node: > ts-node --compiler-options {module:CommonJS,esModuleInterop:true,...} SyntaxError: Expected property name or '}' in JSON at position 1 Cross-platform quoting of JSON-on-cmdline is a notorious pain. apps/portal-bff/tsconfig.app.json already declares all the options we need (module=commonjs, esModuleInterop=true, target=es2021, moduleResolution=node, types=[node]). Point ts-node at it with -P and drop the inline JSON entirely. ts-node --transpile-only ignores the tsconfig's `include`/`exclude` fields for the file passed explicitly, so the fact that seed.ts is under prisma/ (not src/) doesn't matter.