@prisma/orm-postgres runtime loads the whole toolchain through family__control, so production installs carry esbuild, prettier and the CLI engine

Open
#30,928 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
55/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
bun, javascript, postgresql, typescript

Research direction

Start with dist/runtime.mjs in @prisma/orm-postgres and follow the import chain through adapter__runtime.mjs, family__control.mjs, and control-1JIbMzKB.mjs to the toolchain import. Run the Bun reproduction to confirm that @prisma/orm-postgres/runtime fails after removing @prisma/orm-toolchain. Done means the runtime no longer imports control-plane or toolchain code, a production install can load it without those packages, and relevant package/import tests pass.

Written by the indexing model from the issue text.

Description

Package and version

@prisma/[email protected], with @prisma/orm-target-postgres, @prisma/orm-family-sql and @prisma/orm-toolchain at the same version, and @prisma/[email protected].

What happened?

A production install of the PostgreSQL runtime includes the ORM toolchain and everything it brings: esbuild, prettier, vscode-languageserver, clipanion, @prisma/cli-engine and @prisma/management-api-sdk.

@prisma/orm-postgres, @prisma/orm-target-postgres and @prisma/orm-family-sql all list @prisma/orm-toolchain in dependencies, and @prisma/orm-toolchain requires @prisma/cli-engine as a peer at an exact version.

In a minimal install, this tooling is 28 MB of the 85 MB in node_modules. The application only runs queries, so none of it does any work there.

It is more than a declared dependency. Without these packages, the runtime entry does not load:

error: Cannot find module '@prisma/orm-toolchain/migration-tools/spaces'

The static import chain from the runtime entry is:

@prisma/orm-postgres/dist/runtime.mjs
@prisma/orm-target-postgres/dist/adapter__runtime.mjs
@prisma/orm-target-postgres/dist/adapter-DJoHcCZV-B6ixkVJl.mjs
@prisma/orm-target-postgres/dist/contract-contributions-DS1YZqxl-B1ZaAkPj.mjs
@prisma/orm-family-sql/dist/family__control.mjs
@prisma/orm-family-sql/dist/control-1JIbMzKB.mjs   (line 30)
@prisma/orm-toolchain/migration-tools/spaces       (assertDescriptorSelfConsistency)

So the runtime adapter loads the control-plane entry of the SQL family, and through it the toolchain.

What did you expect to happen?

@prisma/orm-postgres/runtime should load no control-plane code, and a production install should not need @prisma/orm-toolchain or @prisma/cli-engine.

Minimal reproduction
mkdir toolchain-in-runtime && cd toolchain-in-runtime
cat > package.json <<'JSON'
{ "private": true, "dependencies": { "@prisma/orm-postgres": "8.0.0-rc.22", "temporal-polyfill": "1.0.6", "typescript": "6.0.3" } }
JSON
bun install --production --ignore-scripts
ls node_modules/esbuild node_modules/prettier node_modules/@prisma/cli-engine
du -sm node_modules

# Remove the tooling, then load the runtime entry.
rm -rf node_modules/@prisma/orm-toolchain
bun -e "await import('@prisma/orm-postgres/runtime')"

The last command fails with the error above. node_modules is 85 MB as installed, 24 MB of which is TypeScript, the optional peer. It is 57 MB once the toolchain, @prisma/cli-engine, @prisma/management-api-sdk, esbuild, @esbuild/*, prettier, clipanion and the vscode-languageserver packages are removed.

Environment
  • Bun 1.4.4 on macOS arm64 for the figures above
  • Same dependency tree in our Linux production image
  • PostgreSQL target, postgres() runtime client
Additional context

#30437 describes the same root cause through @prisma/composer-prisma-cloud. Its proposed fix, publishing migration-tools in a package with no engine peer, would need to cover this path too. Moving assertDescriptorSelfConsistency out of the toolchain, or no longer importing family__control from the runtime adapter, would both remove it.

Deleting these packages from a production image is not a workaround, because the runtime entry stops loading.

— othmane.sayadi

Dominant language
TypeScript
Stars
47.8k
Forks
2.6k
Avg merge
1d 21h
Merged PRs (30d)
227

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from prisma/orm

All issues in prisma/orm

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.