Repository navigation
Description
Verify latest release
- I verified that the issue exists in the latest pnpm release
pnpm version
No response
Which area(s) of pnpm are affected? (leave empty if unsure)
CLI
Link to the code that reproduces this issue or a replay of the bug
No response
Reproduction steps
$ mkdir -p /tmp/pnpm-bin-repro/sub && cd /tmp/pnpm-bin-repro
$ echo '{"name":"repro"}' > package.json
$ mkdir -p node_modules/.bin
$ cd sub
$ npx pnpm@11.25.0 bin
/private/tmp/pnpm-bin-repro/node_modules/.bin
$ npx pnpm@12.3.4 bin
/private/tmp/pnpm-bin-repro/sub/node_modules/.bin
$ ls "$(npx pnpm@12.3.4 bin 2>/dev/null)"
ls: /private/tmp/pnpm-bin-repro/sub/node_modules/.bin: No such file or directoryEvery pnpm 12 release prints the cwd path:
$ for version in 10.0.0 11.0.0 11.24.0 11.25.0 12.0.0 12.1.0 12.2.0 12.3.4; do printf '%-8s ' "$version"; npx -y pnpm@$version bin 2>/dev/null; done
10.0.0 /private/tmp/pnpm-bin-repro/node_modules/.bin
11.0.0 /private/tmp/pnpm-bin-repro/node_modules/.bin
11.24.0 /private/tmp/pnpm-bin-repro/node_modules/.bin
11.25.0 /private/tmp/pnpm-bin-repro/node_modules/.bin
12.0.0 /private/tmp/pnpm-bin-repro/sub/node_modules/.bin
12.1.0 /private/tmp/pnpm-bin-repro/sub/node_modules/.bin
12.2.0 /private/tmp/pnpm-bin-repro/sub/node_modules/.bin
12.3.4 /private/tmp/pnpm-bin-repro/sub/node_modules/.binDescribe the Bug
pnpm 12 prints <cwd>/node_modules/.bin, pnpm 10 and 11 printed the node_modules/.bin of the nearest ancestor directory containing a package.json. Run from a subdirectory, the pnpm 12 path does not exist, so tools spawning executables out of pnpm bin fail with ENOENT. Found in UpLeveled Preflight, which spawns depcheck out of it (upleveled/preflight#774).
#12703 ported the command to Rust as dir.join("node_modules").join(".bin"), describing --dir as "matching pnpm's config.dir (the cwd, not the workspace root)". pnpm 11 resolves config.dir from npm's localPrefix, which is the walk-up to the nearest package.json:
pnpm/pnpm11/config/reader/src/index.ts
Line 309 in a675e91
const cwd = fs.realpathSync(betterPathResolve(cliOptions.dir ?? npmrcResult.localPrefix)) pnpm/pnpm11/config/reader/src/index.ts
Line 503 in a675e91
pnpmConfig.bin = path.join(pnpmConfig.dir, 'node_modules', '.bin')
The change is not mentioned in the pnpm 12 release notes or in What's different in pnpm 12.
Expected Behavior
pnpm bin prints the node_modules/.bin of the nearest ancestor directory containing a package.json, where the project's executables are installed, as in pnpm 10 and 11.
Which Node.js version are you using?
v24.13.0
Which operating systems have you used?
- macOS
- Windows
- Linux
If your OS is a Linux based, which one it is? (Include the version if relevant)
No response
Activity
fix(cli): resolve the working directory to the local prefix (pnpm#14645)
fix(cli): run scripts from the npm project around a Cargo or Python p…
fix(cli): resolve the working directory to the local prefix (pnpm#14645)
fix(cli): run scripts from the npm project around a Cargo or Python p…
chore(deps): update pnpm to v12.4.0