babel-plugin-version-inline
raw JSON → 1.0.0 verified Sat Apr 25 auth: no javascript maintenance
A Babel plugin that replaces the global constant __VERSION__ with the version string from the project's package.json. Version 1.0.0 is stable but receives no active development; it's a simple compile-time macro for including the package version in code without runtime lookup. Unlike runtime version detection or bundler-specific plugins, this works in any Babel build pipeline. It's unmaintained since 2018 and has no dependencies.
Common errors
error ReferenceError: __VERSION__ is not defined ↓
cause The plugin is not applied (Babel not configured or plugin not installed) or the code is run in an environment where __VERSION__ is not defined.
fix
Install the plugin and add 'version-inline' to your Babel plugins list. If running in Node directly (not built), __VERSION__ will not be defined; ensure you run the compiled output.
error Module not found: Can't resolve 'babel-plugin-version-inline' ↓
cause The plugin is not installed in the project's node_modules or Babel cannot find it.
fix
Run
npm install babel-plugin-version-inline --save-dev and ensure you are using the correct plugin name in Babel config. error Cannot find module 'babel-plugin-version-inline' ↓
cause The plugin is not installed or the project's node_modules is missing.
fix
Install the plugin: npm install babel-plugin-version-inline --save-dev
Warnings
deprecated Plugin is no longer maintained; last update in 2018. ↓
fix Consider using @babel/plugin-transform-version-inline or a custom plugin. Alternatively, bundle version info through other means (e.g., environment variables).
gotcha __VERSION__ is replaced at build time; the version string is the one from the project's package.json at the time of build, not at runtime. ↓
fix Ensure your package.json version is updated before building. No runtime fallback.
gotcha The plugin only replaces __VERSION__ exactly; it does not handle other naming conventions like __VERSION or __version__. ↓
fix Use __VERSION__ exactly, or fork the plugin to modify the replacement pattern.
Install
npm install babel-plugin-version-inline yarn add babel-plugin-version-inline pnpm add babel-plugin-version-inline Imports
- default wrong
import plugin from 'babel-plugin-version-inline';correctmodule.exports = require('babel-plugin-version-inline'); - babel config usage wrong
{ "plugins": ["babel-plugin-version-inline"] }correct{ "plugins": ["version-inline"] } - programmatic API wrong
require('babel-core').transform('code', { plugins: [require('babel-plugin-version-inline')] })correctrequire('babel-core').transform('code', { plugins: ['version-inline'] })
Quickstart
// package.json
{
"name": "my-package",
"version": "2.1.0"
}
// .babelrc
{
"plugins": ["version-inline"]
}
// src/index.js
const appVersion = __VERSION__;
console.log(appVersion); // becomes "2.1.0"
// After Babel transformation:
// const appVersion = "2.1.0";
// console.log(appVersion);