{"id":22673,"library":"vite-plugin-generate-package-json","title":"vite-plugin-generate-package-json","description":"Vite plugin that generates a package.json and package-lock.json containing only the packages your Vite bundle actually imports. Useful for creating accurate SBOMs and avoiding false positives in NPM audit/SCA scans caused by misclassified devDependencies. v1.4.0 supports Vite 4–8. Actively maintained with regular updates, written in TypeScript with bundled type definitions. Differentiator: Unlike generic SBOM tools, it only includes runtime dependencies actually bundled, reducing noise in security reports.","status":"active","version":"1.4.0","language":"javascript","source_language":"en","source_url":"https://github.com/maccuaa/vite-plugin-generate-package-json","tags":["javascript","vite","vite-plugin","typescript"],"install":[{"cmd":"npm install vite-plugin-generate-package-json","lang":"bash","label":"npm"},{"cmd":"yarn add vite-plugin-generate-package-json","lang":"bash","label":"yarn"},{"cmd":"pnpm add vite-plugin-generate-package-json","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency required to hook into Vite's build process","package":"vite","optional":false}],"imports":[{"note":"Named export only. Plugin is ESM-only; CommonJS require() is not supported and will fail.","wrong":"import generatePackageJson from 'vite-plugin-generate-package-json'","symbol":"generatePackageJson","correct":"import { generatePackageJson } from 'vite-plugin-generate-package-json'"},{"note":"TypeScript users should use `import type` for the options interface. Not needed for JavaScript.","symbol":"type GeneratePackageJsonOptions","correct":"import type { GeneratePackageJsonOptions } from 'vite-plugin-generate-package-json'"},{"note":"The plugin does not re-export Vite's Plugin type; import it from Vite itself.","wrong":"import { Plugin } from 'vite-plugin-generate-package-json'","symbol":"Plugin","correct":"import { type Plugin } from 'vite'"}],"quickstart":{"code":"// vite.config.ts\nimport { defineConfig } from 'vite';\nimport { generatePackageJson } from 'vite-plugin-generate-package-json';\n\nexport default defineConfig({\n  root: 'src',\n  build: {\n    outDir: 'build',\n  },\n  plugins: [\n    generatePackageJson({\n      outputDir: 'build',\n    }),\n  ],\n});","lang":"typescript","description":"Configures Vite to generate a minimal package.json and package-lock.json in the build output directory containing only the dependencies used by the bundle."},"warnings":[{"fix":"Upgrade to v1.4.0 which supports Vite 4–8, or stick with Vite 5 if using older plugin versions.","message":"v1.3.0 dropped support for Vite 5 and earlier; requires Vite 6+.","severity":"breaking","affected_versions":">=1.3.0 <1.4.0"},{"fix":"Always add generatePackageJson() as the first plugin in the array.","message":"The plugin must be placed before other plugins in the Vite plugins array to correctly capture imports.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Remove `outputDir` and rely on `build.outDir` in Vite config.","message":"The `outputDir` option is deprecated in favor of using Vite's `build.outDir` directly.","severity":"deprecated","affected_versions":">=1.4.0"},{"fix":"Ensure your project and all dependencies are ESM-compatible, or manually include missing packages.","message":"Only ESM modules are processed; CommonJS dependencies may not appear in the generated package.json.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Install with `npm i -D vite-plugin-generate-package-json` and ensure your project uses ESM (type: 'module' in package.json).","cause":"Missing dependency, incorrect import path, or ESM/CJS mismatch.","error":"ERR_MODULE_NOT_FOUND: Cannot find package 'vite-plugin-generate-package-json'"},{"fix":"Change `import generatePackageJson from '...'` to `import { generatePackageJson } from '...'`.","cause":"Using default import instead of named import.","error":"TypeError: generatePackageJson is not a function"},{"fix":"Upgrade Vite to version 4, 5, 6, 7, or 8.","cause":"Outdated Vite version.","error":"Plugin 'vite-plugin-generate-package-json' requires Vite >=4.0.0"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}