# Fix "Cannot find module 'webpack/lib/LoaderTargetPlugin'" With html-webpack-plugin 4

Yes. The agent shows that webpack 5.112 dropped the file html-webpack-plugin 4 requires, moves the plugin to 5, rebuilds, and opens a pull request.

[Run this on Rush](https://cloud.getrush.ai/run/fix-cannot-find-module-webpack-lib-loadertargetplugin/html-webpack-plugin/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

`Error: Cannot find module 'webpack/lib/LoaderTargetPlugin'` started appearing in builds in October 2026, when webpack 5.112.0 stopped shipping that file. html-webpack-plugin 4 requires it by path from `lib/child-compiler.js`; html-webpack-plugin 5 reads `webpack.LoaderTargetPlugin` from the package's export instead. A project on html-webpack-plugin 4 with a caret range on webpack 5 breaks the first time its lockfile resolves 5.112 or later. The run starts with the failing build log, and the agent clones the repository into its own cloud sandbox.

In a library like leezng/vue-json-pretty, `package.json` has `html-webpack-plugin` at `^4.5.2` and `webpack` at `^5.40.0`, with `vue-loader` `^16.2.0`, `mini-css-extract-plugin` `^1.6.0` and `copy-webpack-plugin` `^6.4.1` beside them, and a version 1 `package-lock.json` that resolves webpack 5.94.0. `npm run build` runs `build/build.js` for `build:main` and `build:esm` and then `build:dts`, and that script loads `build/webpack.prod.conf.js`, which adds `HtmlWebpackPlugin` with `example/index.html` as the template and minify options, for the library build as much as for the example. `.github/workflows/gh-pages.yml` runs `npm install` and `npm run build:example`.

The agent reproduces the break by letting the range move: `npm install webpack@latest` resolves 5.112.2, and `npm run build:main` fails with the `Cannot find module` error from the plugin's child compiler. The same build passes on 5.111.1 and 5.94.0, so the boundary is 5.112.0. It then reads what html-webpack-plugin 5 needs: a peer dependency of `webpack ^5.20.0` and Node 10.13 or later, both already satisfied.

The fix is one devDependency: `html-webpack-plugin` to `^5.6.8`. `npm run build:main` then compiles on webpack 5.112.2 with the same single ESLint warning it had before (`no-console` at `src/hooks/useClipboard.ts:14`) and emits `lib/vue-json-pretty.js` and `styles.css`. The agent runs the full `npm run build` so the ESM and type outputs are checked too, and opens the pull request with the lockfile updated.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "npm run build fails with Error: Cannot find module 'webpack/lib/LoaderTargetPlugin'. Show which webpack release removed the file and which plugin requires it, upgrade html-webpack-plugin to a release that works with current webpack 5, confirm its peer dependency and Node requirement are met, run the full build, compare the output and warnings with the build before the change, and open a pull request that names the version boundary.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

What comes back is a pull request that changes one line in `package.json` and the matching entries in `package-lock.json`. Its description names webpack 5.112.0 as the release that removed the file, quotes the error with the plugin's `lib/child-compiler.js` as its source, and shows `npm run build` passing on 5.112.2 with the same warning count as before.

A reviewer checks the generated `example/index.html` against the previous one, since html-webpack-plugin 5 changed some defaults around script tags, and that the `minify` options in `build/webpack.prod.conf.js` still apply. The gh-pages workflow builds the example on the pull request as it does on every push.

If the repository's lockfile already pins a webpack below 5.112, the pull request explains that `npm ci` was never affected and the change protects the next `npm update`; the session keeps the failing and passing builds either way.

## Run it on every failed build on main

Create an automation in the Project with this prompt and a `github` trigger on `workflow_run.failure`. When a push or a dependency bump turns the build red, the run starts with the event after the prompt, reads the job log, finds the module the plugin requires, and opens the pull request.

The same automation with `pull_request.labeled` and the label `dependencies` catches the webpack bump on the Dependabot pull request itself, before it merges, once a maintainer adds the label (a label Dependabot sets when it opens the pull request comes from a bot and fires nothing): the run builds that branch and reports whether the plugin still loads.

## Why run it on Rush?

The error names a file inside `node_modules`, not a line in the project, and it appears only for the webpack version a fresh resolve picks. A Rush run installs the exact versions in its own sandbox, bisects the boundary by installing releases on either side of it, and keeps the build output for each, so the pull request states the boundary as something it ran, not something it read.

Every webpack 5 project still on html-webpack-plugin 4 breaks the same way the week its lockfile moves. Runs go in parallel, one per repository, each with its own bisect, its own one-line fix and its own passing build, and each pull request carries the warning count before and after so a reviewer knows nothing else changed.

## Frequently asked questions

### Can I pin webpack below 5.112 instead?

Yes, `webpack@~5.111` keeps the old plugin working, and the agent offers it in the description as the smaller change. It recommends the plugin upgrade, because the pin freezes webpack's later fixes and html-webpack-plugin 4 is not maintained for webpack 5.

### Does html-webpack-plugin 5 change the generated HTML?

It can: version 5 injects scripts with `defer` and into `head` by default, and its `minify` defaults differ. The agent diffs the example page before and after and lists any change in the pull request; the `minify` options set in `build/webpack.prod.conf.js` are kept.

### Why did the build break without any change in the repository?

`^5.40.0` lets npm resolve any 5.x release. A regenerated lockfile, an `npm update`, or a Dependabot bump moved webpack to 5.112, which no longer ships `lib/LoaderTargetPlugin.js`. The plugin's old major required it by path. The pull request names that boundary.

### Will the other webpack plugins in the project need upgrades too?

The agent runs the whole build after the change, so `mini-css-extract-plugin`, `copy-webpack-plugin` and `vue-loader` are exercised on webpack 5.112.2. Any further error gets its own line in the pull request; in this project the library build passed with no other change.

## More jobs like this: Fix a bug from an alert

- [Fix "ImportError: cannot import name 'cached_download' from 'huggingface_hub'"](https://getrush.ai/run/fix-cannot-import-name-cached-download/huggingface-hub/)
- [Fix "ImportError: cannot import name 'ChatOpenAI' from 'langchain.chat_models'" in LangChain 1.0](https://getrush.ai/run/fix-cannot-import-name-chatopenai-from-langchain-chat-models/langchain/)
- [Fix "ImportError: cannot import name 'compare_ssim' from 'skimage.measure'"](https://getrush.ai/run/fix-cannot-import-name-compare-ssim-from-skimage-measure/scikit-image/)
- [Fix "ImportError: cannot import name 'executor' from 'aiogram'" in a Telegram bot](https://getrush.ai/run/fix-cannot-import-name-executor-from-aiogram/aiogram/)
- [Fix ImportError: Cannot Import Name 'json' From 'itsdangerous' in a Flask 1 App](https://getrush.ai/run/fix-cannot-import-name-json-from-itsdangerous/itsdangerous/)
- [Fix "ImportError: cannot import name 'mock_s3' from 'moto'" in a pytest suite](https://getrush.ai/run/fix-cannot-import-name-mock-s3-from-moto/moto/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
