{"id":22768,"library":"vite-plugin-package-version","title":"vite-plugin-package-version","description":"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.","status":"active","version":"1.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/smnhgn/vite-plugin-package-version","tags":["javascript","vite","typescript","package","version","environment"],"install":[{"cmd":"npm install vite-plugin-package-version","lang":"bash","label":"npm"},{"cmd":"yarn add vite-plugin-package-version","lang":"bash","label":"yarn"},{"cmd":"pnpm add vite-plugin-package-version","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency required for plugin integration","package":"vite","optional":false}],"imports":[{"note":"ESM-only module; CommonJS require is not supported. TypeScript types are included.","wrong":"const version = require('vite-plugin-package-version')","symbol":"default","correct":"import version from 'vite-plugin-package-version'"},{"note":"Use default import; named export does not exist.","wrong":"import { version } from 'vite-plugin-package-version'","symbol":"version","correct":"import version from 'vite-plugin-package-version'"},{"note":"The plugin defines the variable only in import.meta.env, not process.env.","wrong":"process.env.PACKAGE_VERSION","symbol":"PACKAGE_VERSION","correct":"const pkgVersion = import.meta.env.PACKAGE_VERSION"}],"quickstart":{"code":"// vite.config.js\nimport { defineConfig } from 'vite';\nimport version from 'vite-plugin-package-version';\n\nexport default defineConfig({\n  plugins: [version()],\n});\n\n// In your application code (e.g., main.ts):\nconst appVersion = import.meta.env.PACKAGE_VERSION;\nconsole.log('App version:', appVersion);","lang":"typescript","description":"Shows installation, plugin setup in vite.config.js, and usage of the injected PACKAGE_VERSION env variable."},"warnings":[{"fix":"Upgrade Vite to version 2.0.0-beta.69 or later.","message":"Plugin only works with Vite >=2.0.0-beta.69. Older versions are not supported.","severity":"gotcha","affected_versions":"<2.0.0-beta.69"},{"fix":"Use dynamic import or build-time replacement if needed outside Vite environment.","message":"The 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.","severity":"gotcha","affected_versions":"all"},{"fix":"Parse with Number() or use string methods as appropriate.","message":"import.meta.env.PACKAGE_VERSION is a string. Using it in numeric operations may cause NaN.","severity":"gotcha","affected_versions":"all"},{"fix":"Ensure package.json is in the root directory of the Vite project.","message":"The plugin expects the project's package.json at the project root. If placed elsewhere, the version may be incorrect.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Run 'npm install vite-plugin-package-version' and ensure import uses default style.","cause":"Package not installed or incorrect import path.","error":"Error: Cannot find module 'vite-plugin-package-version'"},{"fix":"Add version() to plugins array in vite.config.js.","cause":"Plugin not added to Vite config or version() not called.","error":"import.meta.env.PACKAGE_VERSION is undefined"},{"fix":"Move access inside a function or component that runs after Vite resolves.","cause":"Accessing import.meta.env before plugin initialization.","error":"TypeError: Cannot read properties of undefined (reading 'PACKAGE_VERSION')"},{"fix":"Use import syntax or set type: 'module' in package.json.","cause":"Using CommonJS require() on an ESM-only package.","error":"require() of ES Module not supported"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}