Registry / devops / generate-package-json-webpack-plugin

generate-package-json-webpack-plugin

JSON →
library2.7.0jsnpmunverified

A Webpack plugin that generates a minimal package.json containing only the external dependencies actually used by your bundle. Version 2.7.0 is current, with regular updates. It works with Webpack 4 and 5, and is typically paired with webpack-node-externals. Key differentiators: automatic version resolution from node_modules, support for excluding dependencies, forcing a Webpack version in mixed environments (e.g., Nx), and flexibility to add non-code dependencies with explicit version prefixes. Ships TypeScript types.

npm install generate-package-json-webpack-plugin
INSTALL
IMPORT
SIG · GENERATE-PACKAGE-J
G
generate-package-json-webpack-plugin
devopsjavascriptv2.7.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import GeneratePackageJsonPlugin from 'generate-package-json-webpack-plugin'
const GeneratePackageJsonPlugin = require('generate-package-json-webpack-plugin')
ESM default import. CJS require also works (CommonJS package).
GeneratePackageJsonPlugin
import GeneratePackageJsonPlugin from 'generate-package-json-webpack-plugin'
TypeScript types are shipped; use default import with esModuleInterop or require().
GeneratePackageJsonPlugin
const GeneratePackageJsonPlugin = require('generate-package-json-webpack-plugin')
const { GeneratePackageJsonPlugin } = require('generate-package-json-webpack-plugin')
It's a default export, not a named export. The named export pattern is incorrect.

Minimal Webpack config using the plugin with webpack-node-externals and an excluded dependency.

import GeneratePackageJsonPlugin from 'generate-package-json-webpack-plugin'; import nodeExternals from 'webpack-node-externals'; const basePackage = { name: 'my-app', version: '1.0.0', main: 'dist/index.js', engines: { node: '>= 14' } }; export default { target: 'node', entry: './src/index.js', output: { path: './dist', filename: 'index.js' }, externals: [nodeExternals()], plugins: [ new GeneratePackageJsonPlugin(basePackage, { excludeDependencies: ['aws-sdk'] }) ] };
Debug
Known issues
breakingIn v2.0.0, the API was simplified: only two parameters (basePackage and options) are accepted. Passing basePackageValues as second argument is deprecated.
fix
Update to use options object: new GeneratePackageJsonPlugin(basePackage, { useInstalledVersions: true, ... })
affects: >=2.0.0 <2.1.0
breakingIn v2.0.0, useInstalledVersions default changed from false to true. If you relied on versions from a separate package.json, you must now explicitly set useInstalledVersions: false.
fix
Set options.useInstalledVersions: false if you want to use a separate versions package.json file.
affects: >=2.0.0
deprecatedIn v2.0.0, the old way of specifying versionsPackageFiles as a separate argument is removed. Use versionsPackageFiles inside the options object.
fix
new GeneratePackageJsonPlugin(basePackage, { versionsPackageFiles: ['path/to/versions.json'] })
affects: >=2.0.0
gotchaThe plugin only includes dependencies that are marked as externals in the Webpack config. If a module is not external, it won't appear in the generated package.json.
fix
Use webpack-node-externals or manually externalize node_modules.
affects: >=1.0.0
gotchaWhen using Webpack 5, the plugin may incorrectly detect the Webpack version in mixed environments (e.g., Nx). Versions 2.2.0+ have a forceWebpackVersion option to resolve this.
fix
Set forceWebpackVersion: 'webpack4' or 'webpack5' in options.
affects: >=2.2.0
Errors
Common errors & fixes
TypeError: GeneratePackageJsonPlugin is not a constructor
Importing the plugin with named import syntax instead of default import.
fix
Use `import GeneratePackageJsonPlugin from 'generate-package-json-webpack-plugin'` or `const GeneratePackageJsonPlugin = require('generate-package-json-webpack-plugin')`.
Error: Cannot find module 'webpack'
Webpack is not installed as a peer dependency.
fix
Run `npm install webpack --save-dev`.
Error: No output package.json generated
No external modules were used, or all modules are bundled (not externalized).
fix
Ensure you have externalized node_modules using webpack-node-externals or similar, and that your code imports at least one external module.
Error: version not found for module 'some-module'
The module is installed but the plugin cannot find its version, possibly due to a resolver issue in newer Node versions.
fix
Update to plugin version >=2.3.0 or ensure the module's package.json is accessible.
Upgrade
Version history
2.7.0latest on npm
Audit
Dependencies
webpackrequiredPeer dependency; plugin runs as a Webpack plugin.
Agent activity
2 hits · last 30 days
node
2
Resources
generate-package-json-webpack-plugin — npm install generate-package-json-webpack-plugin · libregistry