From 6a12794b1107d06a903b258c84a7690ec1ef093e Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Wed, 10 Nov 2021 09:06:31 +0100 Subject: [PATCH 1/2] check hooks for existance before using in ProfilingPlugin --- lib/debug/ProfilingPlugin.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/debug/ProfilingPlugin.js b/lib/debug/ProfilingPlugin.js index fa3d266527c..8f8dcaac814 100644 --- a/lib/debug/ProfilingPlugin.js +++ b/lib/debug/ProfilingPlugin.js @@ -203,15 +203,17 @@ class ProfilingPlugin { // Compiler Hooks Object.keys(compiler.hooks).forEach(hookName => { - compiler.hooks[hookName].intercept( - makeInterceptorFor("Compiler", tracer)(hookName) - ); + const hook = compiler.hooks[hookName]; + if (hook) { + hook.intercept(makeInterceptorFor("Compiler", tracer)(hookName)); + } }); Object.keys(compiler.resolverFactory.hooks).forEach(hookName => { - compiler.resolverFactory.hooks[hookName].intercept( - makeInterceptorFor("Resolver", tracer)(hookName) - ); + const hook = compiler.resolverFactory.hooks[hookName]; + if (hook) { + hook.intercept(makeInterceptorFor("Resolver", tracer)(hookName)); + } }); compiler.hooks.compilation.tap( @@ -303,7 +305,7 @@ const interceptAllHooksFor = (instance, tracer, logLabel) => { if (Reflect.has(instance, "hooks")) { Object.keys(instance.hooks).forEach(hookName => { const hook = instance.hooks[hookName]; - if (!hook._fakeHook) { + if (hook && !hook._fakeHook) { hook.intercept(makeInterceptorFor(logLabel, tracer)(hookName)); } }); From 11bc877b42954b9912f0573e53416373e954cbd9 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Wed, 10 Nov 2021 15:03:44 +0100 Subject: [PATCH 2/2] add test case --- test/ProfilingPlugin.test.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/ProfilingPlugin.test.js b/test/ProfilingPlugin.test.js index de3a6766989..f28b3c1d166 100644 --- a/test/ProfilingPlugin.test.js +++ b/test/ProfilingPlugin.test.js @@ -25,7 +25,10 @@ describe("Profiling Plugin", function () { new webpack.debug.ProfilingPlugin({ outputPath: finalPath }) - ] + ], + experiments: { + backCompat: false + } }); compiler.run(err => { if (err) return done(err);