Skip to content
Latchkey

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.

webpack output
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:12

Common 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.

Terminal
# example: a plugin's v5-compatible major
npm install some-webpack-plugin@latest
npm ls webpack   # confirm a single, matching webpack version

Deduplicate Webpack

  1. Run npm ls webpack to find every Webpack version in the tree.
  2. Align peers so there is one Webpack copy (dedupe, or pin via overrides/resolutions).
  3. 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.

Related guides

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