rollup-plugin-merge
raw JSON → 0.2.1 verified Mon Apr 27 auth: no javascript
A Rollup plugin to merge multiple JSON files into a single JSON output during the build process. Current stable version is 0.2.1, with no recent updates and a small scope. It supports recursive merging, watching for changes, and optional pretty-printing. Unlike general-purpose merge tools, it integrates directly into Rollup's plugin system. Use with caution due to infrequent maintenance.
Common errors
error Error [ERR_REQUIRE_ESM]: require() of ES Module not supported. ↓
cause Package is ESM-only, but CommonJS require() is used.
fix
Use import instead: import merge from 'rollup-plugin-merge'
error TypeError: merge is not a function ↓
cause Importing the plugin incorrectly (e.g., named import instead of default).
fix
Use default import: import merge from 'rollup-plugin-merge'
error Plugin error: Cannot find module 'rollup-plugin-merge' ↓
cause Package not installed or missing from node_modules.
fix
Run npm install rollup-plugin-merge --save-dev
Warnings
gotcha The 'recursive' option is misspelled as 'recurisve' in the documentation; use 'recursive' (correct spelling) in config. ↓
fix Use 'recursive' instead of 'recurisve' in the options object.
deprecated No updates since 2019; may not work with latest Rollup versions (v3+). ↓
fix Consider alternatives like @rollup/plugin-json or manual merging.
gotcha Plugin uses CJS internally, but package is ESM-only; may cause issues in mixed module environments. ↓
fix Ensure your project is configured for ESM imports.
gotcha Watching ('watch' option) only copies files on start; does not trigger full rebuild. ↓
fix Set 'watch: true' only if you want initial copy; use Rollup's watch mode for rebuilds.
Install
npm install rollup-plugin-merge yarn add rollup-plugin-merge pnpm add rollup-plugin-merge Imports
- default wrong
const merge = require('rollup-plugin-merge')correctimport merge from 'rollup-plugin-merge' - MergeOptions
import type { MergeOptions } from 'rollup-plugin-merge' - rollup-plugin-merge wrong
import { default as merge } from 'rollup-plugin-merge'correctimport merge from 'rollup-plugin-merge'
Quickstart
import merge from 'rollup-plugin-merge';
export default {
input: 'src/index.js',
output: {
file: 'dist/bundle.js',
format: 'iife',
name: 'app'
},
plugins: [
merge({
input: ['src/file1.json', 'src/file2.json'],
output: 'dist/config.json',
recursive: true,
prettify: true,
watch: true
})
]
};