You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 1d24ff7
Browse filesBrowse the repository at this point in the historyBrowse files
fix(cli): CLI.SECOND_PACKAGE_COPY gives the bin path of the project's prisma unless it is installed in the current folder (#424)
## What the user sees
`prisma` refuses an ORM or Composer command with
`CLI.SECOND_PACKAGE_COPY` when the `prisma` you ran would load a
different copy of the ORM packages than your project's own. The refusal
is right: values made by one copy are rejected by the other. Its advice
is to run the project's own `prisma` instead. In one case that advice
did not work.
In prisma/pdp-control-plane, a pnpm monorepo, a user ran the workspace
root's `prisma contract emit` in
`services/control-plane/scripts/usage-testing/`. That folder has no
`package.json`. The project's own `prisma` there is
`services/control-plane/node_modules/prisma`, two folders up:
```text
# Before: pnpm runs the workspace root's prisma, the one that was just refused
✘ [CLI.SECOND_PACKAGE_COPY] prisma contract emit cannot run here: …
→ pnpm exec prisma contract emit
# After: the advice names the prisma the error found
✘ [CLI.SECOND_PACKAGE_COPY] prisma contract emit cannot run here: …
→ ../../node_modules/.bin/prisma contract emit
```
On Windows the path is `..\..\node_modules\.bin\prisma`, which cmd.exe
and PowerShell both run.
## Why
The error finds the project's `prisma` the way Node does: it walks up
from the current folder to the nearest `node_modules/prisma`. The advice
then ran `prisma` through the package manager (`pnpm exec`, `npx
--no-install`, `yarn exec`, `bunx --no-install`), and the package
managers do not all look in the same place:
- pnpm 10.34.9 (the incident's version) looks in the current folder's
`node_modules/.bin` and then the workspace root's, skipping the folders
between. So it ran the root's `prisma`.
- pnpm 10.27, tried locally, fails in a folder with `node_modules` but
no `package.json`.
- npx and bunx walk up from the nearest folder with a `package.json`,
which usually finds the right one. Yarn was not tried.
A path to the bin runs the right `prisma` with every package manager.
The runner form runs it with every package manager only when the
project's `prisma` is installed in the current folder and that folder
has a `package.json`. So the advice now uses the runner form only in
that case, and the path otherwise. That gives npm and Bun users a path
in some folders where their runner would also have worked. We accept
that: the advice must work wherever it is given, and the error cannot
tell which runner's search the user's version does.
## What changes
- `packages/cli/src/second-copy.ts`: the rule above. The advice keeps
any `--config` the user gave. The platform is passed in, so the tests
check both path forms on any machine.
- `packages/cli/src/lib/package-copies.ts`: the finder also returns the
`node_modules` folder it found `prisma` in. The bin path is built from
that folder as found, not from the package's real path, because under
pnpm the real path is inside `node_modules/.pnpm`, which has no `.bin`.
- `docs/reference/error-reference.md`: the `CLI.SECOND_PACKAGE_COPY`
entry states the rule. It also corrects two runners it named wrongly
(`yarn run` and `bun run`; the code uses `yarn exec` and `bunx
--no-install`).
## How it was checked
- New tests in `tests/second-copy.test.ts` cover the incident's layout,
`--config`, a `prisma` in a folder with no `package.json`, a
`package.json` with `prisma` only further up, and the Windows form.
Removing either condition of the rule fails a test.
- `tests/second-copy.test.ts` and `tests/package-copies.test.ts` pass.
Typecheck and lint are clean.
- A separate reviewer reviewed the code. Its findings are fixed.
## Alternatives considered
- **Always give the bin path.** Rejected: where the runner surely works,
`pnpm exec prisma` is the form users know, and it reads the same on
every system.
- **Point the runner at the right package** (for example `pnpm --filter
<package> exec`). Rejected: the folder may belong to no package, as in
the incident, and each package manager needs its own form.
Agent: cobain-55
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Signed-off-by: willbot <w.a.madden+machine@gmail.com>
Signed-off-by: Will Madden <madden@prisma.io>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: docs/reference/error-reference.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -238,7 +238,7 @@ A prompt with no declared default was reached where it cannot be shown — under
238
238
239
239
### CLI.SECOND_PACKAGE_COPY
240
240
241
-
An ORM or Composer command was refused because the project has its own copy of a Prisma package the command loads (`@prisma/orm-toolchain` or `@prisma/orm-framework`, and `@prisma/composer` for Composer commands), and the running `prisma` would load a different copy: another version, or the same version installed in another place, such as a global `prisma`. Values made by one copy are refused by the other, and what the command writes is read later by the project's own copy, so the run stops before the project's `prisma.config.ts` is evaluated. Refused are the commands that read the project's config, plus `orm init` (it loads the project's own ORM packages and writes files the project reads) and `lsp` (it loads the project's config itself); `emulator list` is not refused. The project's copies are looked for from one directory: the directory of the `--config` file (its real path, when it is a link) when one is given, otherwise the directory of the nearest `prisma.config.ts` at or above the current directory within the repository (the first directory with a `.git` entry), otherwise the current directory. From there, the nearest `node_modules/<package>` up to the repository root counts. Config files further up, and `parent` links, are not followed, so a copy beside a repository-wide config does not refuse a package's own command. Nor are files the config points to in another directory, most often the contract source: they load the packages from where they are, so a copy beside them is not compared. A package the project does not install, or whose copy cannot be read, is not checked. The summary names the first package that differs and both versions; `why` gives every differing package with both versions and both locations, and says so when the versions are equal. Next actions: when the project has its own `prisma`, it is not the one running, and it would not be refused, a run-command with the command path, and the `--config` the user gave, in a form that never downloads a package (`npx --no-install prisma`, `pnpm exec prisma`, `yarn run prisma`, `bun run prisma`); the user adds their other arguments, which are left out because they can hold a database URL; when that `prisma` is reachable only through `--config`, the same advice in words. When the `prisma` the user would run is refused too, the versions to change the project's packages to, or the project's versions a `prisma` release must use; for the same version installed twice, to reinstall the project's dependencies. When the project has no `prisma`, to install it in the project and run that one. Raised by the shell before the command runs; if the check itself fails, nothing is refused. `--help` is unaffected. Exits 2. Meta: `command` (the command path, such as `db migrate`), `packages` (a list of `{ name, project: { version, path }, cli: { version, path } }`).
241
+
An ORM or Composer command was refused because the project has its own copy of a Prisma package the command loads (`@prisma/orm-toolchain` or `@prisma/orm-framework`, and `@prisma/composer` for Composer commands), and the running `prisma` would load a different copy: another version, or the same version installed in another place, such as a global `prisma`. Values made by one copy are refused by the other, and what the command writes is read later by the project's own copy, so the run stops before the project's `prisma.config.ts` is evaluated. Refused are the commands that read the project's config, plus `orm init` (it loads the project's own ORM packages and writes files the project reads) and `lsp` (it loads the project's config itself); `emulator list` is not refused. The project's copies are looked for from one directory: the directory of the `--config` file (its real path, when it is a link) when one is given, otherwise the directory of the nearest `prisma.config.ts` at or above the current directory within the repository (the first directory with a `.git` entry), otherwise the current directory. From there, the nearest `node_modules/<package>` up to the repository root counts. Config files further up, and `parent` links, are not followed, so a copy beside a repository-wide config does not refuse a package's own command. Nor are files the config points to in another directory, most often the contract source: they load the packages from where they are, so a copy beside them is not compared. A package the project does not install, or whose copy cannot be read, is not checked. The summary names the first package that differs and both versions; `why` gives every differing package with both versions and both locations, and says so when the versions are equal. Next actions: when the project has its own `prisma`, it is not the one running, and it would not be refused, a run-command with the command path, and the `--config` the user gave, in a form that never downloads a package: the package manager's runner (`npx --no-install prisma`, `pnpm exec prisma`, `yarn exec prisma`, `bunx --no-install prisma`) when that `prisma` is installed in the current directory and the directory has a `package.json`, otherwise the path of its bin from the current directory, such as `../../node_modules/.bin/prisma` (`..\..\node_modules\.bin\prisma` on Windows), because the runners do not search parent folders the way Node does; the user adds their other arguments, which are left out because they can hold a database URL; when that `prisma` is reachable only through `--config`, the same advice in words. When the `prisma` the user would run is refused too, the versions to change the project's packages to, or the project's versions a `prisma` release must use; for the same version installed twice, to reinstall the project's dependencies. When the project has no `prisma`, to install it in the project and run that one. Raised by the shell before the command runs; if the check itself fails, nothing is refused. `--help` is unaffected. Exits 2. Meta: `command` (the command path, such as `db migrate`), `packages` (a list of `{ name, project: { version, path }, cli: { version, path } }`).
0 commit comments