diff --git a/.changeset/cute-cars-mix.md b/.changeset/cute-cars-mix.md new file mode 100644 index 0000000000..feca2769d8 --- /dev/null +++ b/.changeset/cute-cars-mix.md @@ -0,0 +1,6 @@ +--- +"@pnpm/fs.hard-link-dir": patch +"pnpm": patch +--- + +Handle ENOENT errors thrown by `fs.linkSync()`, which can occur in containerized environments (OverlayFS) instead of EXDEV. The operation now gracefully falls back to `fs.copyFileSync()` in these cases [#10217](https://github.com/pnpm/pnpm/issues/10217). diff --git a/fs/hard-link-dir/src/index.ts b/fs/hard-link-dir/src/index.ts index 5d3a835c42..d5ec3670bb 100644 --- a/fs/hard-link-dir/src/index.ts +++ b/fs/hard-link-dir/src/index.ts @@ -92,7 +92,12 @@ function linkOrCopy (srcFile: string, destFile: string): void { try { gfs.linkSync(srcFile, destFile) } catch (err: unknown) { - if (!(util.types.isNativeError(err) && 'code' in err && err.code === 'EXDEV')) throw err - gfs.copyFileSync(srcFile, destFile) + // In some container environments (OverlayFS), linkSync throws ENOENT + // instead of EXDEV when linking across layers. We must fallback to copy in this case too. + if (util.types.isNativeError(err) && 'code' in err && (err.code === 'EXDEV' || err.code === 'ENOENT')) { + gfs.copyFileSync(srcFile, destFile) + } else { + throw err + } } }