@@ -120,9 +120,7 @@ const mfLog = new Log(LogLevel.WARN);
120120const __filename = fileURLToPath ( import . meta. url ) ;
121121const __dirname = path . dirname ( __filename ) ;
122122const DIST_PATH = path . resolve ( __dirname , ".." ) ;
123- const POOL_WORKER_PATH = path . join ( DIST_PATH , "worker" , "index.mjs" ) ;
124-
125- const NODE_URL_PATH = path . join ( DIST_PATH , "worker" , "lib" , "node" , "url.mjs" ) ;
123+ const POOL_WORKER_PATH = path . join ( DIST_PATH , "worker/index.mjs" ) ;
126124
127125const symbolizerWarning =
128126 "warning: Not symbolizing stack traces because $LLVM_SYMBOLIZER is not set." ;
@@ -463,6 +461,7 @@ function buildProjectWorkerOptions(
463461 runnerWorker . compatibilityFlags
464462 ) ;
465463
464+ // Force nodejs_compat_v2 flag, even if it is disabled by the user, since we require this native stuff for Vitest to work properly
466465 if ( mode !== "v2" ) {
467466 if ( hasNoNodejsCompatV2Flag ) {
468467 runnerWorker . compatibilityFlags . splice (
@@ -578,12 +577,26 @@ function buildProjectWorkerOptions(
578577 path : path . join ( modulesRoot , DEFINES_MODULE_PATH ) ,
579578 contents : defines ,
580579 } ,
581- // The workerd provided `node:url` module doesn't support everything Vitest needs.
582- // As a short-term fix, inject a `node:url` polyfill into the worker bundle
580+ // The native workerd provided nodejs modules don't always support everything Vitest needs.
581+ // As a short-term fix, inject polyfills into the worker bundle that override the native modules.
583582 {
584583 type : "ESModule" ,
585584 path : path . join ( modulesRoot , "node:url" ) ,
586- contents : fs . readFileSync ( NODE_URL_PATH ) ,
585+ contents : fs . readFileSync (
586+ path . join ( DIST_PATH , "worker/lib/node/url.mjs" )
587+ ) ,
588+ } ,
589+ {
590+ type : "ESModule" ,
591+ path : path . join ( modulesRoot , "node:vm" ) ,
592+ contents : fs . readFileSync ( path . join ( DIST_PATH , "worker/lib/node/vm.mjs" ) ) ,
593+ } ,
594+ {
595+ type : "ESModule" ,
596+ path : path . join ( modulesRoot , "node:console" ) ,
597+ contents : fs . readFileSync (
598+ path . join ( DIST_PATH , "worker/lib/node/console.mjs" )
599+ ) ,
587600 } ,
588601 ] ;
589602
0 commit comments