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

vite-plugin-generate-package-json

JSON →
library1.4.0jsnpmunverified

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.

npm install vite-plugin-generate-package-json
INSTALL
IMPORT
SIG · VITE-PLUGIN-GENERA
V
vite-plugin-generate-package-json
devopsjavascriptv1.4.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 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

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

generatePackageJson
import { generatePackageJson } from 'vite-plugin-generate-package-json'
import generatePackageJson from 'vite-plugin-generate-package-json'
Named export only. Plugin is ESM-only; CommonJS require() is not supported and will fail.
type GeneratePackageJsonOptions
import type { GeneratePackageJsonOptions } from 'vite-plugin-generate-package-json'
TypeScript users should use `import type` for the options interface. Not needed for JavaScript.
Plugin
import { type Plugin } from 'vite'
import { Plugin } from 'vite-plugin-generate-package-json'
The plugin does not re-export Vite's Plugin type; import it from Vite itself.

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.

// vite.config.ts import { defineConfig } from 'vite'; import { generatePackageJson } from 'vite-plugin-generate-package-json'; export default defineConfig({ root: 'src', build: { outDir: 'build', }, plugins: [ generatePackageJson({ outputDir: 'build', }), ], });
Debug
Known issues
breakingv1.3.0 dropped support for Vite 5 and earlier; requires Vite 6+.
fix
Upgrade to v1.4.0 which supports Vite 4–8, or stick with Vite 5 if using older plugin versions.
affects: >=1.3.0 <1.4.0
gotchaThe plugin must be placed before other plugins in the Vite plugins array to correctly capture imports.
fix
Always add generatePackageJson() as the first plugin in the array.
affects: >=1.0.0
deprecatedThe `outputDir` option is deprecated in favor of using Vite's `build.outDir` directly.
fix
Remove `outputDir` and rely on `build.outDir` in Vite config.
affects: >=1.4.0
gotchaOnly ESM modules are processed; CommonJS dependencies may not appear in the generated package.json.
fix
Ensure your project and all dependencies are ESM-compatible, or manually include missing packages.
affects: >=1.0.0
Errors
Common errors & fixes
ERR_MODULE_NOT_FOUND: Cannot find package 'vite-plugin-generate-package-json'
Missing dependency, incorrect import path, or ESM/CJS mismatch.
fix
Install with `npm i -D vite-plugin-generate-package-json` and ensure your project uses ESM (type: 'module' in package.json).
TypeError: generatePackageJson is not a function
Using default import instead of named import.
fix
Change `import generatePackageJson from '...'` to `import { generatePackageJson } from '...'`.
Plugin 'vite-plugin-generate-package-json' requires Vite >=4.0.0
Outdated Vite version.
fix
Upgrade Vite to version 4, 5, 6, 7, or 8.
Upgrade
Version history
1.4.0latest on npm
Audit
Dependencies
viterequiredpeer dependency required to hook into Vite's build process
Agent activity
12 hits · last 30 days
node
10
OpenAI (training)
1
Resources
vite-plugin-generate-package-json — npm install vite-plugin-generate-package-json · libregistry