Skip to content
Latchkey

Webpack "Cannot read properties of undefined (reading 'tap')" plugin mismatch in CI

A plugin called .tap() on a Webpack hook that is undefined for the installed Webpack version. The plugin and the Webpack core were built against different major versions, so the hook the plugin expects is not there.

What this error means

The build throws "TypeError: Cannot read properties of undefined (reading 'tap')" inside a plugin's apply method, often after a dependency bump that changed Webpack or a plugin major version.

webpack
TypeError: Cannot read properties of undefined (reading 'tap')
    at SomePlugin.apply (/app/node_modules/some-webpack-plugin/index.js:42:31)
    at Compiler.newCompilation (/app/node_modules/webpack/lib/Compiler.js:1142:30)

Common causes

A plugin built for a different Webpack major

A Webpack 4 plugin taps hooks removed or renamed in Webpack 5 (or vice versa); the hook resolves to undefined, so .tap throws.

A duplicate or mismatched Webpack in the tree

Two copies of Webpack are installed and the plugin loads against the one whose hook surface it does not match.

How to fix it

Align plugin and Webpack versions

  1. Read the plugin name from the stack trace.
  2. Install a plugin version whose peer range includes your Webpack major.
  3. Re-run the build so the plugin taps a hook that exists.
Terminal
npm install some-webpack-plugin@latest webpack@5
npm ls webpack

Deduplicate Webpack in the tree

Ensure a single Webpack version resolves so plugins tap the same hook surface.

Terminal
npm dedupe
npm ls webpack

How to prevent it

  • Upgrade Webpack and its plugins together, not piecemeal.
  • Keep one Webpack version in the dependency tree.
  • Check each plugin's peerDependencies range before bumping.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →