Registry / devops / babel-plugin-inline-json

babel-plugin-inline-json

JSON →
library2.1.0jsnpmunverified

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.

npm install babel-plugin-inline-json
INSTALL
IMPORT
SIG · BABEL-PLUGIN-INLIN
B
babel-plugin-inline-json
devopsjavascriptv2.1.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
plugins: [['inline-json', options]]
plugins: ['babel-plugin-inline-json']
Must be configured in Babel plugins array with options object. The plugin name is 'inline-json' without 'babel-plugin-' prefix.

Shows how to configure the plugin in .babelrc to inline values from a JSON file matching 'config', and the resulting replacement.

// .babelrc or babel.config.js { "plugins": [ ["inline-json", { "matchPattern": "config" }] ] } // config.json { "apiUrl": "https://api.example.com", "timeout": 5000 } // src/index.js import { apiUrl, timeout } from 'config'; // replaced with values console.log(apiUrl, timeout); // Output: https://api.example.com 5000
Debug
Known issues
gotchaPlugin does not work if the argument to require() is an identifier or template literal — only string literals are supported.
fix
Use a string literal, e.g., require('config') instead of require(fileName).
affects: >=0.0.0
breakingVersion 2.x dropped support for Babel 6. Requires Babel 7+.
fix
Upgrade to Babel 7 or use version 1.x for Babel 6.
affects: >=2.0.0
deprecatedThe 'matchPattern' option only accepts a single string, not an array or regex object.
fix
Pass a single string regex pattern (e.g., 'config') for module names to match.
affects: >=2.0.0
Errors
Common errors & fixes
Error: Module 'babel-plugin-inline-json' not found
Plugin not installed or misspelled in Babel config.
fix
Run 'npm install --save-dev babel-plugin-inline-json' and ensure the config uses 'inline-json' without 'babel-plugin-' prefix.
TypeError: Cannot read property 'path' of undefined
Using an identifier as the require argument instead of a string literal.
fix
Replace the require argument with a string literal, e.g., require('config') instead of const file = 'config'; require(file);
Upgrade
Version history
2.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
babel-plugin-inline-json — npm install babel-plugin-inline-json · libregistry