{"id":22098,"library":"rollup-plugin-json-combine","title":"rollup-plugin-json-combine","description":"Rollup plugin that combines multiple JSON files from a directory into a single output file. Current stable version is 1.0.7, with no release cadence documented. It differs from other JSON bundling plugins by providing a custom merge callback, allowing users to define how individual file contents are merged. Requires Node ^14.18.0 or >=16. Ships TypeScript types for better developer experience.","status":"active","version":"1.0.7","language":"javascript","source_language":"en","source_url":null,"tags":["javascript","rollup","json","typescript"],"install":[{"cmd":"npm install rollup-plugin-json-combine","lang":"bash","label":"npm"},{"cmd":"yarn add rollup-plugin-json-combine","lang":"bash","label":"yarn"},{"cmd":"pnpm add rollup-plugin-json-combine","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Package is ESM-only due to Rollup plugin conventions. Default export is the plugin function.","wrong":"const jsonCombine = require('rollup-plugin-json-combine')","symbol":"default","correct":"import jsonCombine from 'rollup-plugin-json-combine'"},{"note":"TypeScript type for plugin options, available only when using TypeScript.","wrong":"","symbol":"RollupPluginJsonCombineOptions","correct":"import type { RollupPluginJsonCombineOptions } from 'rollup-plugin-json-combine'"},{"note":"TypeScript type for the merge callback function signature.","wrong":"","symbol":"MergeCallback","correct":"import type { MergeCallback } from 'rollup-plugin-json-combine'"}],"quickstart":{"code":"import jsonCombine from 'rollup-plugin-json-combine';\n\nexport default {\n  input: 'src/index.js',\n  output: {\n    file: 'dist/bundle.js',\n    format: 'esm'\n  },\n  plugins: [\n    jsonCombine({\n      input: ['locales/*.json'],\n      fileName: 'dist/locales.json',\n      merge: (items) => {\n        const output = {};\n        items.forEach((item) => {\n          output[item.name.replace('.json', '')] = item.res;\n        });\n        return output;\n      },\n    }),\n  ],\n};","lang":"typescript","description":"Combines all JSON files in locales/ into a single dist/locales.json with keys derived from file names."},"warnings":[{"fix":"If you need the parsed value, call JSON.parse(item.res) inside the merge callback.","message":"The merge callback receives items as an array of { name, res } where 'res' is a string (raw content), not a parsed JSON object.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always pass an array: ['path/*.json']","message":"Input option must be an array of glob patterns. Providing a single string (e.g., 'path/*.json') is not supported and may cause no files to be matched.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Ensure the path in fileName is correct relative to your output directory. For example, if output.file is 'dist/bundle.js', use 'dist/locales.json'.","message":"The fileName option is required and must be relative to your Rollup output directory, not the project root.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"","message":"No known deprecations in current version.","severity":"deprecated","affected_versions":""}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Verify the pattern is correct and files exist. Use absolute paths or correct relative paths from process.cwd().","cause":"Input pattern does not match any files or the path is incorrect relative to the project root.","error":"Error: No files matched for input pattern: path/*.json"},{"fix":"Ensure at least one JSON file matches the input pattern. Add error handling in the merge callback.","cause":"The merge callback is called with undefined or non-array data, possibly because input pattern matched no files.","error":"TypeError: items.forEach is not a function"},{"fix":"Check the input pattern and file existence.","cause":"Same as above; merge callback receives undefined when no files are matched.","error":"Error: [plugin: json-combine] Cannot read properties of undefined (reading 'forEach')"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}