{"id":20017,"library":"event-hooks-webpack-plugin","title":"Event Hooks Webpack Plugin","description":"Execute arbitrary JavaScript code on any available Webpack compiler hook. Version 3.0.1 is the latest stable release as of 2025. The plugin provides a simple way to tap into Webpack's compilation lifecycle events (e.g., run, compile, done) by mapping hook names to callback functions. Compared to webpack-shell-plugin, it allows running code (not shell commands) and supports all Tapable hook types via named exports tap, tapAsync, and tapPromise. This package is ESM-only since v3.0.0, requires Node.js with ESM support, Webpack ≥5.82.0, and TypeScript ≥5.5.2. It ships with TypeScript declarations and is released on npm with irregular cadence.","status":"active","version":"3.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/cascornelissen/event-hooks-webpack-plugin","tags":["javascript","event","hook","webpack","plugin","typescript"],"install":[{"cmd":"npm install event-hooks-webpack-plugin","lang":"bash","label":"npm"},{"cmd":"yarn add event-hooks-webpack-plugin","lang":"bash","label":"yarn"},{"cmd":"pnpm add event-hooks-webpack-plugin","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency: required at runtime to access compiler hooks","package":"webpack","optional":false},{"reason":"Peer dependency: required for type checking when using TypeScript","package":"typescript","optional":true}],"imports":[{"note":"Default export; ESM-only since v3.0.0, CommonJS require will fail.","wrong":"const EventHooksPlugin = require('event-hooks-webpack-plugin')","symbol":"EventHooksPlugin","correct":"import EventHooksPlugin from 'event-hooks-webpack-plugin'"},{"note":"Named export for synchronous tap hooks; ESM-only.","wrong":"const { tap } = require('event-hooks-webpack-plugin')","symbol":"tap","correct":"import { tap } from 'event-hooks-webpack-plugin'"},{"note":"Named export for promise-based tap hooks; common mistake is to use tapAsync for promises.","wrong":null,"symbol":"tapPromise","correct":"import { tapPromise } from 'event-hooks-webpack-plugin'"},{"note":"Named export for callback-based tap hooks (e.g., using done callback).","wrong":null,"symbol":"tapAsync","correct":"import { tapAsync } from 'event-hooks-webpack-plugin'"}],"quickstart":{"code":"import EventHooksPlugin, { tapPromise, tapAsync } from 'event-hooks-webpack-plugin';\nimport path from 'path';\nimport { fileURLToPath } from 'url';\n\nconst __dirname = path.dirname(fileURLToPath(import.meta.url));\n\nexport default {\n  entry: './src/index.js',\n  output: {\n    path: path.resolve(__dirname, 'dist'),\n    filename: 'bundle.js',\n  },\n  plugins: [\n    new EventHooksPlugin({\n      compile: () => {\n        console.log('Compilation started...');\n      },\n      emit: tapPromise(async (compilation) => {\n        const assets = Object.keys(compilation.assets);\n        console.log('Assets being emitted:', assets);\n      }),\n      done: tapAsync((stats, callback) => {\n        console.log('Build completed in', stats.endTime - stats.startTime, 'ms');\n        callback();\n      }),\n    }),\n  ],\n};\n","lang":"typescript","description":"Shows default export usage and named tap exports (tapPromise, tapAsync) for different hook types in a Webpack config."},"warnings":[{"fix":"Switch from require() to import statements. Use .mjs extension or configure \"type\": \"module\" in package.json.","message":"Package is ESM-only since v3.0.0. You must use import statements or a compatible ESM loader.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Replace Task with tap, CallbackTask with tapAsync, PromiseTask with tapPromise.","message":"Exports for Task, CallbackTask, and PromiseTask removed in v3.0.0. They are replaced by tap, tapAsync, and tapPromise.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Upgrade Webpack to >=5.82.0.","message":"Dropped support for Webpack versions below 5.82.0. Plugin will not work with Webpack 4 or early Webpack 5.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Upgrade to v3.0.0+ and migrate to ESM.","message":"Version 2.x is deprecated; no longer receiving updates or security fixes.","severity":"deprecated","affected_versions":">=2.0.0 <3.0.0"},{"fix":"Use tapAsync for callback style hooks; for promise hooks, simply return a Promise.","message":"When using tapPromise, do not call the callback parameter — it is not provided. Only return a Promise.","severity":"gotcha","affected_versions":">=3.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Convert your webpack config to ESM: use import statements, rename file to .mjs, or add \"type\": \"module\" to package.json.","cause":"Using CommonJS require() with ESM-only package.","error":"require() of ES Module /path/to/node_modules/event-hooks-webpack-plugin/index.js from /path/to/webpack.config.js not supported."},{"fix":"Run npm install event-hooks-webpack-plugin webpack@^5.82.0 typescript@^5.5.2 --save-dev","cause":"Missing or misconfigured peer dependency (TypeScript or Webpack) or package not installed.","error":"Cannot find module 'event-hooks-webpack-plugin'"},{"fix":"Ensure you are using v3.0.0+ and import correctly: import { tapPromise } from 'event-hooks-webpack-plugin'.","cause":"Trying to import named exports from v2.x or incorrect import path.","error":"TypeError: (0 , _eventHooksWebpackPlugin.tapPromise) is not a function"},{"fix":"Use tap (sync) for hooks that are not async; check Webpack docs for hook type.","cause":"Using tapAsync (callback) on a sync-only hook like 'initialize'.","error":"Error: Hook type not supported: tapAsync for 'initialize' hook"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}