html-bundler-webpack-plugin: Unpredictably, after a random number of runs, Webpack compilation fails.
Current behaviour
Unpredictably, after a random number of runs, Webpack compilation fails if the same resource file is loaded into different templates.
error:
[webpack-cli] HookWebpackError: Cannot read properties of undefined (reading 'endsWith')
at makeWebpackError (/workspace/node_modules/webpack/lib/HookWebpackError.js:48:9)
at /workspace/node_modules/webpack/lib/Compilation.js:3217:12
at eval (eval at create (/workspace/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:41:1)
at fn (/workspace/node_modules/webpack/lib/Compilation.js:499:17)
at _next1 (eval at create (/workspace/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:39:1)
at eval (eval at create (/workspace/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:53:1)
at fn (/workspace/node_modules/webpack/lib/Compilation.js:511:9)
at _next0 (eval at create (/workspace/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:49:1)
at eval (eval at create (/workspace/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:64:1)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
-- inner error --
TypeError: Cannot read properties of undefined (reading 'endsWith')
at Integrity.processAssets (/workspace/node_modules/html-bundler-webpack-plugin/src/Plugin/Extras/Integrity.js:128:62)
at fn (/workspace/node_modules/webpack/lib/Compilation.js:497:10)
at _next1 (eval at create (/workspace/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:39:1)
at eval (eval at create (/workspace/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:53:1)
at fn (/workspace/node_modules/webpack/lib/Compilation.js:511:9)
at _next0 (eval at create (/workspace/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:49:1)
at eval (eval at create (/workspace/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:64:1)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
caused by plugins in Compilation.hooks.processAssets
TypeError: Cannot read properties of undefined (reading 'endsWith')
at Integrity.processAssets (/workspace/node_modules/html-bundler-webpack-plugin/src/Plugin/Extras/Integrity.js:128:62)
at fn (/workspace/node_modules/webpack/lib/Compilation.js:497:10)
at _next1 (eval at create (/workspace/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:39:1)
at eval (eval at create (/workspace/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:53:1)
at fn (/workspace/node_modules/webpack/lib/Compilation.js:511:9)
at _next0 (eval at create (/workspace/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:49:1)
at eval (eval at create (/workspace/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:64:1)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
npm error Lifecycle script `build` failed with error:
npm error code 2
Expected behaviour
Webpack compilation completes without errors.
Reproduction
src/home.html
<!DOCTYPE html>
<html>
<head>
<title>Home</title>
</head>
<body>
<h1>Hello World!</h1>
<script src="./main.js"></script>
</body>
</html>
src/about.html
<!DOCTYPE html>
<html>
<head>
<title>About</title>
</head>
<body>
<h1>Hello World!</h1>
<!-- load the same script with a different URL -->
<script src="./main.js?q=1"></script>
</body>
</html>
src/main.js
console.log('Hello World!');
webpack.config.js
const path = require("node:path");
const HtmlBundlerPlugin = require("html-bundler-webpack-plugin");
module.exports = {
mode: "production",
output: {
path: path.join(__dirname, "dist/"),
},
plugins: [
new HtmlBundlerPlugin({
entry: {
index: "./src/home.html",
about: "./src/about.html",
},
}),
],
};
- repository URL
- example code
Environment
- OS: Debian
- version of Node.js: v22.12.0
- version of Webpack: 5.97.1
- version of the Plugin: 4.13.0
Additional context
Appreciation for the useful project
- After the problem is resolved, do not forget to give a star ⭐
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 30 (30 by maintainers)
Commits related to this issue
- fix: improve handling exceptions in integrity module, #143 — committed to webdiscus/html-bundler-webpack-plugin by webdiscus 2 years ago
- fix: unpredictably Webpack compilation fails after a random number of runs, #143 — committed to webdiscus/html-bundler-webpack-plugin by webdiscus 2 years ago
I found a solution for this second Webpack bug! I can fix it on my side.
oh nooo.
After the fix this excepttion I found other Webpack bug, yet more bad.
In this unpredictably case when the sequence of processing modules is changed, Webpack generate a singe JS file but with double content:
source ./main.js
wrong generated output file dist/main.fde2c043.js:
In heavy production configurations the probability of an error increases to 100%. But without
integrityparameter, compilations complete successfully.I don’t know what’s more surprising - catching this error using Webpack as a static HTML generator or finding the right line in a file with more than 2000 lines)
I found the BUG in the Webpack:
vralle/issue-143-preload-