{"id":19083,"library":"babel-plugin-inline-json","title":"babel-plugin-inline-json","description":"A Babel plugin that inlines values from JSON files (e.g., config files) at build time, replacing require() calls to matched files with the actual JSON values. Current stable version is 2.1.0, with infrequent releases. Key differentiator: simple static replacement without runtime overhead, but does not work if the require argument is an identifier or template literal. Alternative to Webpack's DefinePlugin for Babel-only workflows.","status":"active","version":"2.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/gkatsev/babel-plugin-inline-json","tags":["javascript","babel","plugin","babel-plugin"],"install":[{"cmd":"npm install babel-plugin-inline-json","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-inline-json","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-inline-json","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Must be configured in Babel plugins array with options object. The plugin name is 'inline-json' without 'babel-plugin-' prefix.","wrong":"plugins: ['babel-plugin-inline-json']","symbol":"default","correct":"plugins: [['inline-json', options]]"}],"quickstart":{"code":"// .babelrc or babel.config.js\n{\n  \"plugins\": [\n    [\"inline-json\", { \"matchPattern\": \"config\" }]\n  ]\n}\n\n// config.json\n{\n  \"apiUrl\": \"https://api.example.com\",\n  \"timeout\": 5000\n}\n\n// src/index.js\nimport { apiUrl, timeout } from 'config'; // replaced with values\nconsole.log(apiUrl, timeout);\n// Output: https://api.example.com 5000","lang":"javascript","description":"Shows how to configure the plugin in .babelrc to inline values from a JSON file matching 'config', and the resulting replacement."},"warnings":[{"fix":"Use a string literal, e.g., require('config') instead of require(fileName).","message":"Plugin does not work if the argument to require() is an identifier or template literal — only string literals are supported.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Upgrade to Babel 7 or use version 1.x for Babel 6.","message":"Version 2.x dropped support for Babel 6. Requires Babel 7+.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Pass a single string regex pattern (e.g., 'config') for module names to match.","message":"The 'matchPattern' option only accepts a single string, not an array or regex object.","severity":"deprecated","affected_versions":">=2.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-json' and ensure the config uses 'inline-json' without 'babel-plugin-' prefix.","cause":"Plugin not installed or misspelled in Babel config.","error":"Error: Module 'babel-plugin-inline-json' not found"},{"fix":"Replace the require argument with a string literal, e.g., require('config') instead of const file = 'config'; require(file);","cause":"Using an identifier as the require argument instead of a string literal.","error":"TypeError: Cannot read property 'path' of undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}