Webpack "Cannot read properties of undefined (reading 'tap')"
A plugin tried to tap into a Webpack compiler hook that is undefined for the Webpack version you are running. This is a version-mismatch between Webpack and one of its plugins or loaders.
What this error means
The build crashes during plugin setup with Cannot read properties of undefined (reading 'tap') (or the older Cannot read property 'tap' of undefined), with a stack pointing into a plugin. It is deterministic - a dependency/peer mismatch, not flake.
TypeError: Cannot read properties of undefined (reading 'tap')
at SomeWebpackPlugin.apply (/app/node_modules/some-plugin/index.js:42:33)
at /app/node_modules/webpack/lib/webpack.js:120:12Common causes
Plugin built for a different Webpack major
Webpack 5 reorganized hooks and dropped some that Webpack 4 plugins relied on. A plugin written for v4 reaches a hook that is undefined on v5 (or vice versa) and crashes calling .tap on it.
Mismatched/duplicate Webpack versions
A tool (CRA, Storybook, a framework) pins one Webpack version while a plugin pulls in another, so the plugin taps a compiler instance from a different Webpack copy.
How to fix it
Upgrade the plugin to match Webpack
Install the plugin release that supports your Webpack major version.
# example: a plugin's v5-compatible major
npm install some-webpack-plugin@latest
npm ls webpack # confirm a single, matching webpack versionDeduplicate Webpack
- Run
npm ls webpackto find every Webpack version in the tree. - Align peers so there is one Webpack copy (dedupe, or pin via overrides/resolutions).
- Re-install from a clean lockfile so the resolved tree is reproducible.
How to prevent it
- Upgrade Webpack and its plugins/loaders together, not piecemeal.
- Keep a single Webpack version in the tree (
npm ls webpack). - Check a plugin's supported Webpack range before adding or bumping it.