Skip to content

Commit 2f3678c

Browse files
authored
fix: disable v8-compile-cache when using npm@>=9.7.0 (#276)
Node.js segfaults when using `npm@>=9.7.0` and `v8-compile-cache` ```console $ docker run -it node:20.3.0-slim corepack npm@9.7.1 --version [SIGSEGV] ```
1 parent 17d1f3d commit 2f3678c

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

sources/corepackUtils.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ export async function installVersion(installTarget: string, locator: Locator, {s
169169
/**
170170
* Loads the binary, taking control of the current process.
171171
*/
172-
export async function runVersion(installSpec: { location: string, spec: PackageManagerSpec }, binName: string, args: Array<string>): Promise<void> {
172+
export async function runVersion(locator: Locator, installSpec: { location: string, spec: PackageManagerSpec }, binName: string, args: Array<string>): Promise<void> {
173173
let binPath: string | null = null;
174174
if (Array.isArray(installSpec.spec.bin)) {
175175
if (installSpec.spec.bin.some(bin => bin === binName)) {
@@ -191,8 +191,12 @@ export async function runVersion(installSpec: { location: string, spec: PackageM
191191
if (!binPath)
192192
throw new Error(`Assertion failed: Unable to locate path for bin '${binName}'`);
193193

194-
// @ts-expect-error - No types
195-
await import(`v8-compile-cache`);
194+
// Node.js segfaults when using npm@>=9.7.0 and v8-compile-cache
195+
// $ docker run -it node:20.3.0-slim corepack npm@9.7.1 --version
196+
// [SIGSEGV]
197+
if (locator.name !== `npm` || semver.lt(locator.reference, `9.7.0`))
198+
// @ts-expect-error - No types
199+
await import(`v8-compile-cache`);
196200

197201
// We load the binary into the current process,
198202
// while making it think it was spawned.

sources/main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ async function executePackageManagerRequest({packageManager, binaryName, binaryV
8585

8686
const installSpec = await context.engine.ensurePackageManager(resolved);
8787

88-
return await corepackUtils.runVersion(installSpec, binaryName, args);
88+
return await corepackUtils.runVersion(resolved, installSpec, binaryName, args);
8989
}
9090

9191
export async function runMain(argv: Array<string>) {

0 commit comments

Comments
 (0)