webpack-license-plugin
raw JSON → 4.5.1 verified Sat Apr 25 auth: no javascript
A webpack plugin that extracts open source license information from npm packages in your webpack output. Current stable version is 4.5.1, released with regular updates. It supports webpack 2 through 5 and helps generate a bill of materials in JSON, HTML, CSV, or custom formats. Key differentiators include built-in license policy enforcement (fail on unacceptable licenses), exclusion of internal packages, and full test coverage. Since v4.4.1, the package ships both ESM and CJS builds with TypeScript types, and requires Node >=16.
Common errors
error Module not found: Error: Can't resolve 'webpack-license-plugin' ↓
cause The package is not installed or the import path is incorrect.
fix
Run
npm install -D webpack-license-plugin or yarn add -D webpack-license-plugin and ensure your import uses the correct path. error TypeError: LicensePlugin is not a constructor ↓
cause Using a named import instead of default import when importing from ESM.
fix
Use
import LicensePlugin from 'webpack-license-plugin' (default import) instead of import { LicensePlugin } from 'webpack-license-plugin'. error Error: Cannot find module 'webpack' ↓
cause Webpack is not installed or is a peer dependency missing.
fix
Install webpack:
npm install webpack or yarn add webpack. Warnings
breaking Requires Node >=16 as of v4.5.0; earlier versions may work on Node 12 but are not supported. ↓
fix Upgrade Node to version 16 or later.
gotcha The plugin taps into webpack's compilation hooks; if using webpack 5's persistent caching, ensure the plugin is not excluded from caching (it uses tapAsync which is cacheable by default). ↓
fix If you encounter stale license output, clear the webpack cache or configure the plugin to run on every build.
deprecated The option `licenseOverrides` was used in earlier versions but is not documented in v4; instead use `additionalFiles` or custom output. ↓
fix Migrate to the new options schema (see README).
gotcha When using output format other than JSON, the custom renderer function must be provided – otherwise the plugin outputs JSON by default. ↓
fix Set the `outputFormatter` option to a function that returns the desired format string.
Install
npm install webpack-license-plugin yarn add webpack-license-plugin pnpm add webpack-license-plugin Imports
- LicensePlugin wrong
const LicensePlugin = require('webpack-license-plugin')correctimport LicensePlugin from 'webpack-license-plugin' - LicensePluginOptions
import type { LicensePluginOptions } from 'webpack-license-plugin' - PluginOutput
import type { PluginOutput } from 'webpack-license-plugin'
Quickstart
// webpack.config.js
import LicensePlugin from 'webpack-license-plugin';
export default {
plugins: [
new LicensePlugin({
outputFilename: 'thirdPartyNotice.json',
unacceptableLicenseTest: (licenseIdentifier) =>
['GPL', 'AGPL', 'LGPL', 'MPL'].includes(licenseIdentifier),
excludedPackageTest: (packageName) =>
packageName.startsWith('@mycompany/'),
}),
],
};