@@ -514,62 +514,25 @@ class HtmlRspackPlugin {
514514 const templateWithoutLoaders = templateFilename
515515 . replace ( / ^ .+ ! / , '' )
516516 . replace ( / \? .+ $ / , '' ) ;
517- const vmContext = vm . createContext ( {
518- ...global ,
519- HTML_WEBPACK_PLUGIN : true ,
520- require : require ,
521- htmlWebpackPluginPublicPath : publicPath ,
522- __filename : templateWithoutLoaders ,
523- __dirname : path . dirname ( templateWithoutLoaders ) ,
524- AbortController : global . AbortController ,
525- AbortSignal : global . AbortSignal ,
526- Blob : global . Blob ,
527- Buffer : global . Buffer ,
528- ByteLengthQueuingStrategy : global . ByteLengthQueuingStrategy ,
529- BroadcastChannel : global . BroadcastChannel ,
530- CompressionStream : global . CompressionStream ,
531- CountQueuingStrategy : global . CountQueuingStrategy ,
532- Crypto : global . Crypto ,
533- CryptoKey : global . CryptoKey ,
534- CustomEvent : global . CustomEvent ,
535- DecompressionStream : global . DecompressionStream ,
536- Event : global . Event ,
537- EventTarget : global . EventTarget ,
538- File : global . File ,
539- FormData : global . FormData ,
540- Headers : global . Headers ,
541- MessageChannel : global . MessageChannel ,
542- MessageEvent : global . MessageEvent ,
543- MessagePort : global . MessagePort ,
544- PerformanceEntry : global . PerformanceEntry ,
545- PerformanceMark : global . PerformanceMark ,
546- PerformanceMeasure : global . PerformanceMeasure ,
547- PerformanceObserver : global . PerformanceObserver ,
548- PerformanceObserverEntryList : global . PerformanceObserverEntryList ,
549- PerformanceResourceTiming : global . PerformanceResourceTiming ,
550- ReadableByteStreamController : global . ReadableByteStreamController ,
551- ReadableStream : global . ReadableStream ,
552- ReadableStreamBYOBReader : global . ReadableStreamBYOBReader ,
553- ReadableStreamBYOBRequest : global . ReadableStreamBYOBRequest ,
554- ReadableStreamDefaultController : global . ReadableStreamDefaultController ,
555- ReadableStreamDefaultReader : global . ReadableStreamDefaultReader ,
556- Response : global . Response ,
557- Request : global . Request ,
558- SubtleCrypto : global . SubtleCrypto ,
559- DOMException : global . DOMException ,
560- TextDecoder : global . TextDecoder ,
561- TextDecoderStream : global . TextDecoderStream ,
562- TextEncoder : global . TextEncoder ,
563- TextEncoderStream : global . TextEncoderStream ,
564- TransformStream : global . TransformStream ,
565- TransformStreamDefaultController : global . TransformStreamDefaultController ,
566- URL : global . URL ,
567- URLSearchParams : global . URLSearchParams ,
568- WebAssembly : global . WebAssembly ,
569- WritableStream : global . WritableStream ,
570- WritableStreamDefaultController : global . WritableStreamDefaultController ,
571- WritableStreamDefaultWriter : global . WritableStreamDefaultWriter ,
572- } ) ;
517+ const globalClone = Object . create (
518+ Object . getPrototypeOf ( global ) ,
519+ Object . getOwnPropertyDescriptors ( global ) ,
520+ ) ;
521+
522+ // Presence of `eval` breaks template's explicit `eval` call, might be a bug in Node
523+ delete globalClone . eval ;
524+
525+ // Not using `...global` as it throws when localStorage is not explicitly enabled in Node 25+
526+ const vmContext = vm . createContext (
527+ Object . assign ( globalClone , {
528+ HTML_WEBPACK_PLUGIN : true ,
529+ // Copying nonstandard globals like `require` explicitly as they may be absent from `global`
530+ require : require ,
531+ htmlWebpackPluginPublicPath : publicPath ,
532+ __filename : templateWithoutLoaders ,
533+ __dirname : path . dirname ( templateWithoutLoaders ) ,
534+ } ) ,
535+ ) ;
573536
574537 const vmScript = new vm . Script ( source , {
575538 filename : templateWithoutLoaders ,
0 commit comments