Skip to content

fix(cli): CLI.SECOND_PACKAGE_COPY gives the bin path of the project's prisma unless it is installed in the current folder - #424

Merged
wmadden-electric merged 2 commits into
mainfrom
fix/second-copy-advice-bin-path
Dec 2, 2026
Merged

wmadden-electric merged 2 commits into
mainfrom
fix/second-copy-advice-bin-path

Conversation

@wmadden-electric

Copy link
Copy Markdown
Contributor

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:

# 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

wmadden-electric and others added 2 commits December 2, 2026 21:39
… bin path when the package manager's runner would run another one

From a folder with no package.json inside a pnpm workspace package, the
advice `pnpm exec prisma ...` ran the workspace root's prisma and was
refused again. pnpm 10 looks only in the current directory's
node_modules/.bin and then the workspace root's; pnpm 11 needs a
package.json in the current directory. The runner form is now given only
when the project's prisma is installed in the current directory and that
directory has a package.json; otherwise the advice is the bin's path from
the current directory, such as `../../node_modules/.bin/prisma contract emit`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: willbot <w.a.madden+machine@gmail.com>
Signed-off-by: Will Madden <madden@prisma.io>
…ere it found prisma

On Windows the advised bin path is written with backslashes and left
unquoted (`..\..\node_modules\.bin\prisma`), which cmd.exe and
PowerShell both run; it holds only `.`, `..`, `node_modules`, `.bin`
and `prisma`, so it never needs quoting. The platform comes from the
host process, so both forms are tested on any host.

The project-package finder now returns the node_modules folder it found
the package in, and both the runner decision and the bin path are
derived from it.

Tried with pnpm 10.27 in a workspace: from a folder with a package.json
and no prisma, `pnpm exec prisma` ran the workspace root's prisma; from
a folder with node_modules but no package.json it failed with
ERR_PNPM_RECURSIVE_EXEC_NO_PACKAGE. The earlier commit called that
pnpm 11; it was 10.27, and the claim is gone from the error reference.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: willbot <w.a.madden+machine@gmail.com>
Signed-off-by: Will Madden <madden@prisma.io>
@coderabbitai

coderabbitai Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary by CodeRabbit

  • Bug Fixes
    • Improved Prisma command suggestions for project and workspace setups, including cases where Prisma is installed at the workspace root or is not installed directly in the current folder.
    • Added platform-appropriate path formatting to suggested commands, including on Windows.
  • Documentation
    • Clarified which project-local Prisma invocation options are suggested and when parent-folder lookup is not performed.

Walkthrough

Project Prisma discovery now returns the installation path alongside the package copy. Recovery uses that information to select a package-manager runner or a platform-specific local binary path. The suggested command retains the command path and optional config argument. Tests and reference documentation cover the updated command suggestions.

Merge Risk: Minimal · up to 01af7

This change makes the second-copy recovery advice point to the project's own prisma executable. It affects only the suggested command text, so merge risk is low.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: CLI.SECOND_PACKAGE_COPY advice now points to the project's prisma bin path unless prisma is installed in the current folder. It matches the changes in second-copy.ts, …
Description check Passed The description explains the user-facing error, the incident layout, the package-manager search differences, the new advice rule, the code and docs changes, the tests, and the alternatives considered.…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: CLI.SECOND_PACKAGE_COPY advice now points to the project's prisma bin path unless prisma is installed in the current folder. It matches the changes in second-copy.ts, package-copies.ts, and the docs. The title is long, but it is specific and accurate.

Full details: Description check

Explanation

The description explains the user-facing error, the incident layout, the package-manager search differences, the new advice rule, the code and docs changes, the tests, and the alternatives considered. It is directly related to the changeset.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
Simplify code

  • Commit to this branch
  • Create a new PR
Fix failing CI checks

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 2a148f81-a3bd-4dbd-9a86-125eac4df3e7
Commits

Reviewing files that changed from the base of the PR and between d613f48 and 01af779.

Files selected for processing: 5

  • docs/reference/error-reference.md
  • packages/cli/src/lib/package-copies.ts
  • packages/cli/src/main.ts
  • packages/cli/src/second-copy.ts
  • packages/cli/tests/second-copy.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@pkg-pr-new

pkg-pr-new Bot commented Dec 2, 2026

Copy link
Copy Markdown

Open in StackBlitz

npx https://pkg.pr.new/@prisma/cli@424
npx https://pkg.pr.new/@prisma/cli-engine@424

commit: 01af779

@wmadden-electric
wmadden-electric merged commit 1d24ff7 into main Dec 2, 2026
21 of 22 checks passed
@wmadden-electric
wmadden-electric deleted the fix/second-copy-advice-bin-path branch December 2, 2026 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant