Skip to content

Commit 3bf96e4

Browse files
authored
fix: Dynamically import webpack in webpack plugin (#171)
Dynamically import webpack inside the webpack plugin, resolving issues with NextJS.
1 parent 518f350 commit 3bf96e4

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

.changeset/thin-dryers-joke.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
"@codecov/webpack-plugin": patch
3+
"@codecov/bundler-plugin-core": patch
4+
"@codecov/nextjs-webpack-plugin": patch
5+
"@codecov/nuxt-plugin": patch
6+
"@codecov/remix-vite-plugin": patch
7+
"@codecov/rollup-plugin": patch
8+
"@codecov/solidstart-plugin": patch
9+
"@codecov/sveltekit-plugin": patch
10+
"@codecov/vite-plugin": patch
11+
---
12+
13+
Switch webpack import from top level to dynamic in the webpack base plugin

packages/webpack-plugin/src/webpack-bundle-analysis/webpackBundleAnalysisPlugin.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { type BundleAnalysisUploadPlugin } from "@codecov/bundler-plugin-core";
2-
import * as webpack from "webpack";
2+
import { createRequire } from "node:module";
3+
import type * as TWebpack from "webpack";
34

45
import { processAssets, processChunks, processModules } from "./utils";
56

@@ -25,6 +26,9 @@ export const webpackBundleAnalysisPlugin: BundleAnalysisUploadPlugin = ({
2526
await output.write();
2627
},
2728
webpack(compiler) {
29+
const generatedRequire = createRequire(import.meta.url);
30+
const webpack = generatedRequire("webpack") as typeof TWebpack;
31+
2832
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
2933
compilation.hooks.processAssets.tapPromise(
3034
{

0 commit comments

Comments
 (0)