{"id":20060,"library":"generate-package-json-webpack-plugin","title":"generate-package-json-webpack-plugin","description":"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.","status":"active","version":"2.7.0","language":"javascript","source_language":"en","source_url":"https://github.com/lostpebble/generate-package-json-webpack-plugin","tags":["javascript","webpack","plugin","package.json","node","modules","typescript"],"install":[{"cmd":"npm install generate-package-json-webpack-plugin","lang":"bash","label":"npm"},{"cmd":"yarn add generate-package-json-webpack-plugin","lang":"bash","label":"yarn"},{"cmd":"pnpm add generate-package-json-webpack-plugin","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency; plugin runs as a Webpack plugin.","package":"webpack","optional":false}],"imports":[{"note":"ESM default import. CJS require also works (CommonJS package).","wrong":"const GeneratePackageJsonPlugin = require('generate-package-json-webpack-plugin')","symbol":"default","correct":"import GeneratePackageJsonPlugin from 'generate-package-json-webpack-plugin'"},{"note":"TypeScript types are shipped; use default import with esModuleInterop or require().","wrong":"","symbol":"GeneratePackageJsonPlugin","correct":"import GeneratePackageJsonPlugin from 'generate-package-json-webpack-plugin'"},{"note":"It's a default export, not a named export. The named export pattern is incorrect.","wrong":"const { GeneratePackageJsonPlugin } = require('generate-package-json-webpack-plugin')","symbol":"GeneratePackageJsonPlugin","correct":"const GeneratePackageJsonPlugin = require('generate-package-json-webpack-plugin')"}],"quickstart":{"code":"import GeneratePackageJsonPlugin from 'generate-package-json-webpack-plugin';\nimport nodeExternals from 'webpack-node-externals';\n\nconst basePackage = {\n  name: 'my-app',\n  version: '1.0.0',\n  main: 'dist/index.js',\n  engines: { node: '>= 14' }\n};\n\nexport default {\n  target: 'node',\n  entry: './src/index.js',\n  output: { path: './dist', filename: 'index.js' },\n  externals: [nodeExternals()],\n  plugins: [\n    new GeneratePackageJsonPlugin(basePackage, {\n      excludeDependencies: ['aws-sdk']\n    })\n  ]\n};","lang":"typescript","description":"Minimal Webpack config using the plugin with webpack-node-externals and an excluded dependency."},"warnings":[{"fix":"Update to use options object: new GeneratePackageJsonPlugin(basePackage, { useInstalledVersions: true, ... })","message":"In v2.0.0, the API was simplified: only two parameters (basePackage and options) are accepted. Passing basePackageValues as second argument is deprecated.","severity":"breaking","affected_versions":">=2.0.0 <2.1.0"},{"fix":"Set options.useInstalledVersions: false if you want to use a separate versions package.json file.","message":"In 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.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"new GeneratePackageJsonPlugin(basePackage, { versionsPackageFiles: ['path/to/versions.json'] })","message":"In v2.0.0, the old way of specifying versionsPackageFiles as a separate argument is removed. Use versionsPackageFiles inside the options object.","severity":"deprecated","affected_versions":">=2.0.0"},{"fix":"Use webpack-node-externals or manually externalize node_modules.","message":"The 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Set forceWebpackVersion: 'webpack4' or 'webpack5' in options.","message":"When 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.","severity":"gotcha","affected_versions":">=2.2.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Use `import GeneratePackageJsonPlugin from 'generate-package-json-webpack-plugin'` or `const GeneratePackageJsonPlugin = require('generate-package-json-webpack-plugin')`.","cause":"Importing the plugin with named import syntax instead of default import.","error":"TypeError: GeneratePackageJsonPlugin is not a constructor"},{"fix":"Run `npm install webpack --save-dev`.","cause":"Webpack is not installed as a peer dependency.","error":"Error: Cannot find module 'webpack'"},{"fix":"Ensure you have externalized node_modules using webpack-node-externals or similar, and that your code imports at least one external module.","cause":"No external modules were used, or all modules are bundled (not externalized).","error":"Error: No output package.json generated"},{"fix":"Update to plugin version >=2.3.0 or ensure the module's package.json is accessible.","cause":"The module is installed but the plugin cannot find its version, possibly due to a resolver issue in newer Node versions.","error":"Error: version not found for module 'some-module'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}