@@ -365,6 +365,9 @@ export async function runBundles(
365
365
overlayFS ,
366
366
externalModules ,
367
367
true ,
368
+ target === 'node' ||
369
+ target === 'electron-main' ||
370
+ target === 'react-server' ,
368
371
) ;
369
372
370
373
esmOutput = bundles . length === 1 ? res [ 0 ] : res ;
@@ -927,6 +930,9 @@ function prepareNodeContext(
927
930
readFileSync : ( file , encoding ) => {
928
931
return overlayFS . readFileSync ( file , encoding ) ;
929
932
} ,
933
+ existsSync : file => {
934
+ return overlayFS . existsSync ( file ) ;
935
+ } ,
930
936
} ;
931
937
}
932
938
@@ -939,6 +945,11 @@ function prepareNodeContext(
939
945
return { } ;
940
946
}
941
947
948
+ if ( path . extname ( res ) === '.node' ) {
949
+ // $FlowFixMe[unsupported-syntax]
950
+ return require ( res ) ;
951
+ }
952
+
942
953
let cached = nodeCache . get ( res ) ;
943
954
if ( cached ) {
944
955
return cached . module . exports ;
@@ -1002,6 +1013,7 @@ export async function runESM(
1002
1013
fs: FileSystem,
1003
1014
externalModules: ExternalModules = { } ,
1004
1015
requireExtensions: boolean = false,
1016
+ isNode: boolean = false,
1005
1017
): Promise< Array < { | [ string ] : mixed | } >> {
1006
1018
let id = instanceId ++ ;
1007
1019
let cache = new Map ( ) ;
@@ -1048,7 +1060,11 @@ export async function runESM(
1048
1060
entry ( specifier , referrer ) ,
1049
1061
context,
1050
1062
initializeImportMeta ( meta ) {
1051
- meta . url = `http://localhost/${ path . basename ( filename ) } ` ;
1063
+ if ( isNode ) {
1064
+ meta . url = url . pathToFileURL ( filename ) . toString ( ) ;
1065
+ } else {
1066
+ meta . url = `http://localhost/${ path . basename ( filename ) } ` ;
1067
+ }
1052
1068
} ,
1053
1069
} ) ;
1054
1070
cache . set ( filename , m ) ;
0 commit comments