Registry / devops / merge-json-webpack-plugin

merge-json-webpack-plugin

JSON →
library6.2.1jsnpmunverified

Webpack 5 plugin that merges multiple JSON files into a single output file during the build process. Version 6.2.1 is current, with a stable release cadence. Supports glob patterns for file selection, custom merge functions, optional output minification, and transformation hooks. Differentiates from simple file concatenation by performing deep merge with customizable merge strategy, and integrates directly as a webpack plugin. Requires webpack ^5.0.0 and Node >=12.20.0. Ships TypeScript definitions.

npm install merge-json-webpack-plugin
INSTALL
IMPORT
SIG · MERGE-JSON-WEBPACK
M
merge-json-webpack-plugin
devopsjavascriptv6.2.1
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.

MergeJsonPlugin
const MergeJsonPlugin = require('merge-json-webpack-plugin');
import MergeJsonPlugin from 'merge-json-webpack-plugin';
The package does not export ESM; use CommonJS require in webpack config. Alternatively, if using ES modules for webpack config, use dynamic import: const MergeJsonPlugin = (await import('merge-json-webpack-plugin')).default;
type MergeJsonPluginOptions
import type { MergeJsonPluginOptions } from 'merge-json-webpack-plugin';
TypeScript users can import the options type directly; the package provides bundled types.
MergeJsonPlugin (default import with type assertion)
const MergeJsonPlugin = require('merge-json-webpack-plugin');
import MergeJsonPlugin = require('merge-json-webpack-plugin');
In TypeScript, avoid the import = require syntax; use ordinary require with @types/node or a simple const declaration.

Basic webpack config that merges common.json and overrides.json into manifest.json, with optional version injection and minification.

// webpack.config.js const MergeJsonPlugin = require('merge-json-webpack-plugin'); const path = require('path'); module.exports = { plugins: [ new MergeJsonPlugin({ groups: [ { files: ['common.json', 'overrides.json'], to: 'manifest.json', transform: (merged) => { merged.version = process.env.APP_VERSION || '1.0.0'; return merged; }, }, ], minify: process.env.NODE_ENV === 'production', }), ], };
Debug
Known issues
breakingv5.0.0 dropped support for webpack 4 and Node <12.
fix
Upgrade to webpack 5 and Node >=12.
affects: >=5.0.0
breakingv4.0.0 renamed from 'merge-json-webpack-plugin' (npm scoping change) but package name remained same; the plugin constructor changed from 'MergeJsonWebpackPlugin' to 'MergeJsonPlugin'.
fix
Use 'MergeJsonPlugin' instead of 'MergeJsonWebpackPlugin'.
affects: >=4.0.0
deprecatedThe 'cwd' option may be deprecated in future; use webpack context instead.
fix
Use webpack's context option instead of passing cwd to the plugin.
affects: <7.0.0
gotchaWhen using 'pattern' option, the order of merged JSONs is not guaranteed; subsequent files may overwrite earlier ones arbitrarily.
fix
Use 'files' array instead, or ensure your transform/merge function handles order.
affects: *
gotchaThe 'transform' function must return a JSON-serializable object; returning a non-serializable value (e.g., undefined) will cause the output to be empty or malformed.
fix
Ensure transform always returns an object or null; if returning a promise, it must resolve to a valid object.
affects: *
gotchaUsing 'mergeFn' incorrectly can cause performance issues or infinite loops; custom merge functions are called recursively.
fix
Avoid mutating objects inside mergeFn; always return a new object.
affects: *
Errors
Common errors & fixes
Error: Cannot find module 'merge-json-webpack-plugin'
Missing installation or incorrect import path.
fix
Run `npm install -D merge-json-webpack-plugin`.
TypeError: MergeJsonPlugin is not a constructor
Importing the module incorrectly (e.g., default import vs named import).
fix
Use `const MergeJsonPlugin = require('merge-json-webpack-plugin');`.
ValidationError: Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.
Webpack version mismatch; plugin requires webpack 5.
fix
Update webpack to version 5: `npm install -D webpack@5`.
Error: ENOENT: no such file or directory, open 'path/to/file.json'
One of the source files specified in 'files' does not exist.
fix
Check that all file paths are correct and relative to webpack context or the plugin's cwd.
Upgrade
Version history
6.2.1latest on npm
Audit
Dependencies
webpackrequiredpeer dependency; plugin only works with webpack 5+
fast-globoptionalused for pattern matching when 'pattern' option is specified
Agent activity
2 hits · last 30 days
node
2
Resources
merge-json-webpack-plugin — npm install merge-json-webpack-plugin · libregistry