Repository navigation
Description
Disclosure: I used an agent to create this issue and the fix after a deep-dive investigation of a build issue we encountered.
Last pnpm version that worked
11.28.6
pnpm version
12.14.0 (also 12.10.1 and main at 93b60fd9)
Code to reproduce the issue
package.json:
{
"name": "import-method-repro",
"private": true,
"dependencies": {
"esbuild": "0.25.0",
"is-number": "7.0.0"
}
}pnpm-workspace.yaml:
allowBuilds:
esbuild: true
packageImportMethod: copy
patchedDependencies:
is-number@7.0.0: patches/is-number@7.0.0.patchpatches/is-number@7.0.0.patch:
diff --git a/index.js b/index.js
--- a/index.js
+++ b/index.js
@@ -1,3 +1,4 @@
+// patched
/*!
* is-number <https://github.com/jonschlinkert/is-number>
*Run:
pnpm install --reporter=ndjson 2>&1 \
| node -e 'require("readline").createInterface({ input: process.stdin }).on("line", (l) => { const e = JSON.parse(l); if (e.status === "imported") console.log(e.method, e.to) })'Expected behavior
pnpm 11.28.6 copies every package:
copy .../node_modules/.pnpm/@esbuild+linux-x64@0.25.0/node_modules/@esbuild/linux-x64
copy .../node_modules/.pnpm/esbuild@0.25.0/node_modules/esbuild
copy .../node_modules/.pnpm/is-number@7.0.0_patch_hash=.../node_modules/is-number
Actual behavior
pnpm 12.14.0 clones esbuild, which has a postinstall script, and the patched is-number:
clone .../node_modules/.pnpm/esbuild@0.25.0/node_modules/esbuild
clone .../node_modules/.pnpm/is-number@7.0.0_patch_hash=.../node_modules/is-number
copy .../node_modules/.pnpm/@esbuild+linux-x64@0.25.0/node_modules/@esbuild/linux-x64
Additional information
effective_import_method in pnpm/crates/deps-restorer/src/create_virtual_dir_by_snapshot.rs changes the method to clone-or-copy for every package that a lifecycle script or a patch will still write. The goal is to keep those writes out of the store. An explicit copy already does that, but the override replaces it too. pnpm 11 keeps copy for these packages since 11.28.0 (createPackageImporter in pnpm11/store/create-cafs-store). The comment on effective_import_method says that pnpm 11 applies the same override, which is no longer correct.
This is important on Windows. On ReFS volumes and Dev Drives, a clone of a store file that pnpm wrote a few milliseconds before can have zeros in place of the file data (cargo-bins/reflink-copy#, microsoft/CopyOnWrite#12). We set packageImportMethod: copy on our Windows build machines to stop clones. pnpm 12 still cloned the packages with install scripts or patches. In each install from a new store, 7 to 10 of about 700,000 files were zero-filled, and all of them were in these packages. Installs failed with ERR_PNPM_CMD_SHIM_PARSE_MANIFEST on a zero-filled package.json, and a C compiler failed on a parser.c that is zero after byte 1,048,576.
On Windows, auto also tries a clone first (as the packageImportMethod docs say), so every install on a Dev Drive with default settings clones every package. The fix for that is in reflink-copy (link above). This issue is only about the explicit copy setting.
Node.js version
24.18.1
Operating System
Windows
Contributing a fix
- I am working on a fix
Activity
fix(deps-restorer): keep an explicit `copy` import for built packages (…
Update pnpm to v12.16.1 (#2164)
chore(deps): update pnpm to v12.16.0