Skip to content

TypeError: Cannot read properties of null (reading 'split') in watch mode when a file is deleted #191

Description

@wjgerritsen-0001

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

  • repository URL
  • example code

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions