Registry / devops / vite-plugin-package-version

vite-plugin-package-version

JSON →
library1.1.0jsnpmunverified

Vite plugin that injects the version from package.json into the Vite environment as import.meta.env.PACKAGE_VERSION. Version 1.1.0 is the current stable release; it requires Vite >=2.0.0-beta.69. The plugin is lightweight and focused solely on exposing the package version. Unlike rollup plugins or manual env variable injection, it provides a simple, zero-config approach for Vite projects. No breaking changes reported; TypeScript types are included.

npm install vite-plugin-package-version
INSTALL
IMPORT
SIG · VITE-PLUGIN-PACKAG
V
vite-plugin-package-version
devopsjavascriptv1.1.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.

default
import version from 'vite-plugin-package-version'
const version = require('vite-plugin-package-version')
ESM-only module; CommonJS require is not supported. TypeScript types are included.
version
import version from 'vite-plugin-package-version'
import { version } from 'vite-plugin-package-version'
Use default import; named export does not exist.
PACKAGE_VERSION
const pkgVersion = import.meta.env.PACKAGE_VERSION
process.env.PACKAGE_VERSION
The plugin defines the variable only in import.meta.env, not process.env.

Shows installation, plugin setup in vite.config.js, and usage of the injected PACKAGE_VERSION env variable.

// vite.config.js import { defineConfig } from 'vite'; import version from 'vite-plugin-package-version'; export default defineConfig({ plugins: [version()], }); // In your application code (e.g., main.ts): const appVersion = import.meta.env.PACKAGE_VERSION; console.log('App version:', appVersion);
Debug
Known issues
gotchaPlugin only works with Vite >=2.0.0-beta.69. Older versions are not supported.
fix
Upgrade Vite to version 2.0.0-beta.69 or later.
affects: <2.0.0-beta.69
gotchaThe injected variable is only available at runtime via import.meta.env.PACKAGE_VERSION. It will not be available in Node.js scripts or during build-time config.
fix
Use dynamic import or build-time replacement if needed outside Vite environment.
affects: all
gotchaimport.meta.env.PACKAGE_VERSION is a string. Using it in numeric operations may cause NaN.
fix
Parse with Number() or use string methods as appropriate.
affects: all
gotchaThe plugin expects the project's package.json at the project root. If placed elsewhere, the version may be incorrect.
fix
Ensure package.json is in the root directory of the Vite project.
affects: all
Errors
Common errors & fixes
Error: Cannot find module 'vite-plugin-package-version'
Package not installed or incorrect import path.
fix
Run 'npm install vite-plugin-package-version' and ensure import uses default style.
import.meta.env.PACKAGE_VERSION is undefined
Plugin not added to Vite config or version() not called.
fix
Add version() to plugins array in vite.config.js.
TypeError: Cannot read properties of undefined (reading 'PACKAGE_VERSION')
Accessing import.meta.env before plugin initialization.
fix
Move access inside a function or component that runs after Vite resolves.
require() of ES Module not supported
Using CommonJS require() on an ESM-only package.
fix
Use import syntax or set type: 'module' in package.json.
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies
viterequiredpeer dependency required for plugin integration
Agent activity
5 hits · last 30 days
node
4
Resources
vite-plugin-package-version — npm install vite-plugin-package-version · libregistry