License Webpack Plugin
raw JSON → 4.0.2 verified Sat Apr 25 auth: no javascript
A webpack plugin that extracts third-party library license information and outputs it to a file or adds a banner. Current stable version is 4.0.2. It supports webpack 4 and 5, outputs licenses per chunk or aggregated, and allows exclusion/inclusion patterns. Compared to alternatives, it offers comprehensive configuration for license compliance in webpack builds.
Common errors
error TypeError: LicenseWebpackPlugin is not a constructor ↓
cause Using default import/require without destructuring (e.g., `const LicenseWebpackPlugin = require('license-webpack-plugin')`)
fix
Use
const { LicenseWebpackPlugin } = require('license-webpack-plugin') or import { LicenseWebpackPlugin } from 'license-webpack-plugin' error Error: Cannot find module 'license-webpack-plugin' ↓
cause The package is not installed or installed as devDependency incorrectly.
fix
Run
npm install --save-dev license-webpack-plugin error No license information found for some modules ↓
cause Certain packages do not include license information in their package.json.
fix
Use
licenseTypeOverrides option to manually specify licenses for such packages. Warnings
gotcha The plugin does not automatically scan packages imported via SASS @import or other non-JS modules. ↓
fix Manually specify additional modules using the `additionalModules` option.
gotcha Requires webpack 4 or 5; not compatible with webpack 3 or earlier. ↓
fix Upgrade webpack to version 4 or 5, or use an older version of the plugin (e.g., 2.x) for webpack 3.
gotcha Default output adds a banner to all JavaScript assets; may conflict with CSP (Content Security Policy). ↓
fix Set `addBanner: false` in plugin options to suppress banner injection.
breaking Version 4.x changed default export to named export 'LicenseWebpackPlugin'. ↓
fix Update import from default import to named import: `const { LicenseWebpackPlugin } = require('license-webpack-plugin')`
Install
npm install license-webpack-plugin yarn add license-webpack-plugin pnpm add license-webpack-plugin Imports
- LicenseWebpackPlugin wrong
const LicenseWebpackPlugin = require('license-webpack-plugin');correctconst { LicenseWebpackPlugin } = require('license-webpack-plugin'); - LicenseWebpackPlugin wrong
import LicenseWebpackPlugin from 'license-webpack-plugin';correctimport { LicenseWebpackPlugin } from 'license-webpack-plugin'; - PluginOptions
import { PluginOptions } from 'license-webpack-plugin';
Quickstart
const { LicenseWebpackPlugin } = require('license-webpack-plugin');
module.exports = {
plugins: [
new LicenseWebpackPlugin({
outputFilename: 'licenses.txt',
unacceptableLicenseTest: (licenseType) => licenseType === 'GPL' || licenseType === 'AGPL',
renderLicenses: (modules) => modules.map(m => `Package: ${m.name} - License: ${m.licenseId}`).join('\n'),
})
]
};