{"id":19080,"library":"babel-plugin-inline-constants","title":"babel-plugin-inline-constants","description":"Babel plugin (v5.0.0) to inline constant values from imported modules. Supports ESM (import) and CJS (require). Evaluates specified modules with Node to retrieve primitive values (numbers, strings, booleans, null) and replaces references directly in code for better gzip compression. TypeScript types included, ESM-only, Node 18+. Similar to babel-plugin-transform-define but focuses on module-exported constants.","status":"active","version":"5.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/wooorm/babel-plugin-inline-constants","tags":["javascript","babel","plugin","inline","constant","typescript"],"install":[{"cmd":"npm install babel-plugin-inline-constants","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-inline-constants","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-inline-constants","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency","package":"babel","optional":false}],"imports":[{"note":"ESM-only since v2. CommonJS require is invalid.","wrong":"const inlineConstants = require('babel-plugin-inline-constants')","symbol":"default","correct":"import inlineConstants from 'babel-plugin-inline-constants'"},{"note":"TypeScript type import, not available as runtime value.","wrong":"","symbol":"Options","correct":"import type { Options } from 'babel-plugin-inline-constants'"},{"note":"The modules option is required. Omitting it will cause an error.","wrong":"{\n  \"plugins\": [\"babel-plugin-inline-constants\"]\n}","symbol":".babelrc plugin config","correct":"{\n  \"plugins\": [[\"babel-plugin-inline-constants\", { \"modules\": \"./constants.js\" }]]\n}"}],"quickstart":{"code":"// .babelrc\n{\n  \"plugins\": [[\"babel-plugin-inline-constants\", { \"modules\": [\"./constants.js\"] }]]\n}\n\n// constants.js\nexport const SITE = 'example.com';\nexport const PORT = 8080;\n\n// input.js\nimport { SITE, PORT } from './constants.js';\nconsole.log(`https://${SITE}:${PORT}`);\n\n// output (after babel)\nconsole.log(`https://example.com:8080`);\n","lang":"javascript","description":"Shows how to configure the plugin with a modules list, and how constants are inlined in the output."},"warnings":[{"fix":"Upgrade to Node 18+.","message":"Dropped support for Node 16.","severity":"breaking","affected_versions":">=5.0.0 <5.0.0"},{"fix":"Use import syntax or dynamic import().","message":"Migration to ESM-only. No CommonJS support.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Do not inline untrusted modules.","message":"Modules are evaluated with Node, so only use the plugin if you trust the code.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Always specify modules in plugin options.","message":"The modules option is required; omitting it throws an error.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Ensure constants are primitives.","message":"Only primitives (numbers, strings, booleans, null) are inlined. Objects, arrays, functions are not supported.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run: npm install --save-dev babel-plugin-inline-constants","cause":"Package not installed or installed as devDependency incorrectly.","error":"Error: Cannot find module 'babel-plugin-inline-constants'"},{"fix":"Use import or ensure you are in an ESM context.","cause":"Using require on ESM-only module.","error":"TypeError: inlineConstants is not a function"},{"fix":"Example: { \"plugins\": [[\"babel-plugin-inline-constants\", { \"modules\": [\"./constants.js\"] }]] }","cause":"No modules option provided to the plugin.","error":"Error: babel-plugin-inline-constants: missing required option 'modules'"},{"fix":"Only export primitives (numbers, strings, booleans, null) from constant modules.","cause":"Trying to inline a non-primitive export like an object or function.","error":"Error: Cannot read properties of undefined (reading 'some')"},{"fix":"Ensure module path is correct relative to the Babel working directory.","cause":"Path resolution issue; module path relative to cwd.","error":"Module not found: Can't resolve './my-constants'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}