{"id":19084,"library":"babel-plugin-inline-replace-variables","title":"babel-plugin-inline-replace-variables","description":"A Babel plugin that replaces identifier references with literal values during compilation. Version 1.3.1 is the latest stable release. It supports simple literal replacements (strings, booleans) as well as complex expressions via AST nodes. The plugin is commonly used for compile-time constants like __DEV__ or __VERSION__. Compared to alternatives like babel-plugin-replace-identifiers, this one replaces identifiers with literal values, not other identifiers. Low maintenance and simple API, suitable for projects using Babel 6/7.","status":"maintenance","version":"1.3.1","language":"javascript","source_language":"en","source_url":"https://github.com/wssgcg1213/babel-plugin-inline-replace-variables","tags":["javascript","babel","plugin","inline","replace","variables"],"install":[{"cmd":"npm install babel-plugin-inline-replace-variables","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-inline-replace-variables","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-inline-replace-variables","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency for Babel plugin system","package":"@babel/core","optional":false}],"imports":[{"note":"CommonJS require also works, but ESM pattern shown. Plugin is used in Babel config.","wrong":"const plugin = require('babel-plugin-inline-replace-variables')","symbol":"default (plugin)","correct":"import plugin from 'babel-plugin-inline-replace-variables'"},{"note":"Use short name 'inline-replace-variables' in plugins array, not full package name.","wrong":"['babel-plugin-inline-replace-variables', { '__SERVER__': true }]","symbol":"plugin in .babelrc","correct":"['inline-replace-variables', { '__SERVER__': true }]"},{"note":"Using AST node constructor from babel-types is deprecated; use @babel/types in Babel 7.","wrong":"const t = require('babel-types')","symbol":"t (babel-types)","correct":"import * as t from '@babel/types'"}],"quickstart":{"code":"// .babelrc or babel.config.js\n{\n  \"plugins\": [\n    [\"inline-replace-variables\", {\n      \"__SERVER__\": true,\n      \"__VERSION__\": \"1.0.0\"\n    }]\n  ]\n}\n\n// input.js\nif (__SERVER__) {\n  console.log('Server version:', __VERSION__);\n}\n\n// output.js\nif (true) {\n  console.log('Server version:', \"1.0.0\");\n}","lang":"javascript","description":"Replace __SERVER__ with true and __VERSION__ with a string literal using Babel plugin configuration."},"warnings":[{"fix":"npm uninstall babel-plugin-inline-replace-varibles && npm install babel-plugin-inline-replace-variables","message":"Package name changed: 'babel-plugin-inline-replace-varibles' (misspelled) is deprecated; use 'babel-plugin-inline-replace-variables'.","severity":"deprecated","affected_versions":"<1.0.1"},{"fix":"Use babel-plugin-replace-identifiers for identifier replacement.","message":"Plugin only replaces identifiers with literal values, not other identifiers. If you need identifier-to-identifier replacement, use babel-plugin-replace-identifiers instead.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use { type: 'node', replacement: /* AST node */ } for expression replacements.","message":"When using AST node replacement via 'replacement' property, the node must be a valid Babel AST node; passing a string will be interpreted as a literal value, not a node.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure @babel/core is installed as a dev dependency and that the plugin is compatible (tested with Babel 7+).","message":"Babel 6 vs Babel 7 compatibility: plugin may not work with Babel 7 without adjustment due to peer dependency on @babel/core.","severity":"breaking","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Install the correct package: npm install babel-plugin-inline-replace-variables --save-dev","cause":"Misspelled package name: 'varibles' instead of 'variables'.","error":"Cannot find module 'babel-plugin-inline-replace-varibles'"},{"fix":"Add the plugin to .babelrc with the replacement value for __SERVER__.","cause":"Variable used in source code but not replaced because plugin not configured or not running.","error":"ReferenceError: __SERVER__ is not defined"},{"fix":"Use format: { '__KEY__': { type: 'node', replacement: someASTNode } }","cause":"Trying to use an object replacement without proper 'type' property.","error":"Error: Plugin configuration: [object Object] is not a valid replacement"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}