Current behaviour
In webpack watch mode, deleting any watched source file causes an unhandled crash and terminates the watcher. Webpack's MultiCompiler calls Watching.invalidate(null) when a file is removed from the watch set. The invalidate handler in AssetCompiler passes that null directly to Option.isScript(), which crashes trying to call .split() on it.
Full stack trace:
TypeError: Cannot read properties of null (reading 'split')
at Option.isScript (node_modules/html-bundler-webpack-plugin/src/Plugin/Option.js:606:29)
at HtmlBundlerPlugin.invalidate (node_modules/html-bundler-webpack-plugin/src/Plugin/AssetCompiler.js:529:40)
at Watching.invalidate (node_modules/webpack/lib/Watching.js:407:32)
at MultiCompiler.js:601:38
Expected behaviour
Deleting a watched file should not crash the watcher. The invalidation should be handled gracefully (either skipped or treated as a non-script resource), allowing watch mode to continue running.
Reproduction
Configure webpack with html-bundler-webpack-plugin in a multi-compiler setup (array of configs), start webpack --watch, then delete any source file (.ts/.js) that is part of the watched compilation.
The crash occurs because MultiCompiler propagates the invalidate event with null as the filename to all child compilers, including the one running HtmlBundlerPlugin.
Suggested one-line fix in Option.js:606:
// before
const [file] = resource.split('?', 1);
// after
const [file] = (resource ?? '').split('?', 1);
Environment
- OS: Windows
- version of Node.js: 25.2.1
- version of Webpack: 5.94.0
- version of the Plugin: 4.23.0
Additional context
The crash only occurs in multi-compiler mode. A single-config webpack setup may not trigger this code path because MultiCompiler has different invalidation propagation logic.
Current behaviour
In webpack watch mode, deleting any watched source file causes an unhandled crash and terminates the watcher. Webpack's
MultiCompilercallsWatching.invalidate(null)when a file is removed from the watch set. Theinvalidatehandler inAssetCompilerpasses thatnulldirectly toOption.isScript(), which crashes trying to call.split()on it.Full stack trace:
Expected behaviour
Deleting a watched file should not crash the watcher. The invalidation should be handled gracefully (either skipped or treated as a non-script resource), allowing watch mode to continue running.
Reproduction
Configure webpack with
html-bundler-webpack-pluginin a multi-compiler setup (array of configs), startwebpack --watch, then delete any source file (.ts/.js) that is part of the watched compilation.The crash occurs because
MultiCompilerpropagates the invalidate event withnullas the filename to all child compilers, including the one runningHtmlBundlerPlugin.Suggested one-line fix in
Option.js:606:Environment
Additional context
The crash only occurs in multi-compiler mode. A single-config webpack setup may not trigger this code path because
MultiCompilerhas different invalidation propagation logic.