{"id":20203,"library":"merge-json-webpack-plugin","title":"merge-json-webpack-plugin","description":"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.","status":"active","version":"6.2.1","language":"javascript","source_language":"en","source_url":"https://github.com/sibiraj-s/merge-json-webpack-plugin","tags":["javascript","json-merge","merge-json-webpack-plugin","webpack-plugin","typescript"],"install":[{"cmd":"npm install merge-json-webpack-plugin","lang":"bash","label":"npm"},{"cmd":"yarn add merge-json-webpack-plugin","lang":"bash","label":"yarn"},{"cmd":"pnpm add merge-json-webpack-plugin","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency; plugin only works with webpack 5+","package":"webpack","optional":false},{"reason":"used for pattern matching when 'pattern' option is specified","package":"fast-glob","optional":true}],"imports":[{"note":"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;","wrong":"import MergeJsonPlugin from 'merge-json-webpack-plugin';","symbol":"MergeJsonPlugin","correct":"const MergeJsonPlugin = require('merge-json-webpack-plugin');"},{"note":"TypeScript users can import the options type directly; the package provides bundled types.","wrong":"","symbol":"type MergeJsonPluginOptions","correct":"import type { MergeJsonPluginOptions } from 'merge-json-webpack-plugin';"},{"note":"In TypeScript, avoid the import = require syntax; use ordinary require with @types/node or a simple const declaration.","wrong":"import MergeJsonPlugin = require('merge-json-webpack-plugin');","symbol":"MergeJsonPlugin (default import with type assertion)","correct":"const MergeJsonPlugin = require('merge-json-webpack-plugin');"}],"quickstart":{"code":"// webpack.config.js\nconst MergeJsonPlugin = require('merge-json-webpack-plugin');\nconst path = require('path');\n\nmodule.exports = {\n  plugins: [\n    new MergeJsonPlugin({\n      groups: [\n        {\n          files: ['common.json', 'overrides.json'],\n          to: 'manifest.json',\n          transform: (merged) => {\n            merged.version = process.env.APP_VERSION || '1.0.0';\n            return merged;\n          },\n        },\n      ],\n      minify: process.env.NODE_ENV === 'production',\n    }),\n  ],\n};","lang":"javascript","description":"Basic webpack config that merges common.json and overrides.json into manifest.json, with optional version injection and minification."},"warnings":[{"fix":"Upgrade to webpack 5 and Node >=12.","message":"v5.0.0 dropped support for webpack 4 and Node <12.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Use 'MergeJsonPlugin' instead of 'MergeJsonWebpackPlugin'.","message":"v4.0.0 renamed from 'merge-json-webpack-plugin' (npm scoping change) but package name remained same; the plugin constructor changed from 'MergeJsonWebpackPlugin' to 'MergeJsonPlugin'.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Use webpack's context option instead of passing cwd to the plugin.","message":"The 'cwd' option may be deprecated in future; use webpack context instead.","severity":"deprecated","affected_versions":"<7.0.0"},{"fix":"Use 'files' array instead, or ensure your transform/merge function handles order.","message":"When using 'pattern' option, the order of merged JSONs is not guaranteed; subsequent files may overwrite earlier ones arbitrarily.","severity":"gotcha","affected_versions":"*"},{"fix":"Ensure transform always returns an object or null; if returning a promise, it must resolve to a valid object.","message":"The '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.","severity":"gotcha","affected_versions":"*"},{"fix":"Avoid mutating objects inside mergeFn; always return a new object.","message":"Using 'mergeFn' incorrectly can cause performance issues or infinite loops; custom merge functions are called recursively.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run `npm install -D merge-json-webpack-plugin`.","cause":"Missing installation or incorrect import path.","error":"Error: Cannot find module 'merge-json-webpack-plugin'"},{"fix":"Use `const MergeJsonPlugin = require('merge-json-webpack-plugin');`.","cause":"Importing the module incorrectly (e.g., default import vs named import).","error":"TypeError: MergeJsonPlugin is not a constructor"},{"fix":"Update webpack to version 5: `npm install -D webpack@5`.","cause":"Webpack version mismatch; plugin requires webpack 5.","error":"ValidationError: Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema."},{"fix":"Check that all file paths are correct and relative to webpack context or the plugin's cwd.","cause":"One of the source files specified in 'files' does not exist.","error":"Error: ENOENT: no such file or directory, open 'path/to/file.json'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}