@@ -400,12 +400,16 @@ export async function runVersion(locator: Locator, installSpec: InstallSpec & {s
400400 if ( ! binPath )
401401 throw new Error ( `Assertion failed: Unable to locate path for bin '${ binName } '` ) ;
402402
403- // Node.js segfaults when using npm@>=9.7.0 and v8-compile-cache
404- // $ docker run -it node:20.3.0-slim corepack npm@9.7.1 --version
405- // [SIGSEGV]
406- if ( locator . name !== `npm` || semverLt ( locator . reference , `9.7.0` ) )
407- // @ts -expect-error - No types
408- await import ( `v8-compile-cache` ) ;
403+ // @ts -expect-error - Missing types
404+ if ( ! Module . enableCompileCache ) {
405+ // Node.js segfaults when using npm@>=9.7.0 and v8-compile-cache
406+ // $ docker run -it node:20.3.0-slim corepack npm@9.7.1 --version
407+ // [SIGSEGV]
408+ if ( locator . name !== `npm` || semverLt ( locator . reference , `9.7.0` ) ) {
409+ // @ts -expect-error - No types
410+ await import ( `v8-compile-cache` ) ;
411+ }
412+ }
409413
410414 // We load the binary into the current process,
411415 // while making it think it was spawned.
@@ -429,6 +433,12 @@ export async function runVersion(locator: Locator, installSpec: InstallSpec & {s
429433 // Use nextTick to unwind the stack, and consequently remove Corepack from
430434 // the stack trace of the package manager.
431435 process . nextTick ( Module . runMain , binPath ) ;
436+
437+ // @ts -expect-error - No types
438+ if ( Module . flushCompileCache ) {
439+ // @ts -expect-error - No types
440+ setImmediate ( Module . flushCompileCache ) ;
441+ }
432442}
433443
434444export function shouldSkipIntegrityCheck ( ) {
0 commit comments