{"id":25170,"library":"diffpatch","title":"diffpatch","description":"A JavaScript library for diffing and patching plain objects and arrays, including nested structures. Current stable version is 0.6.0, released as an ES module with TypeScript type definitions. It uses LCS (Longest Common Subsequence) for smart array diffing, supports reverse deltas, unpatching, and optional output formatters. Optionally leverages google-diff-match-patch for long text diffs. Compared to similar libraries, diffpatch focuses on pure JSON delta format and low footprint (~16KB min+gzipped), and requires an objectHash function for object identity matching in arrays.","status":"active","version":"0.6.0","language":"javascript","source_language":"en","source_url":"https://github.com/bpmn-io/diffpatch","tags":["javascript","json","diff","patch","typescript"],"install":[{"cmd":"npm install diffpatch","lang":"bash","label":"npm"},{"cmd":"yarn add diffpatch","lang":"bash","label":"yarn"},{"cmd":"pnpm add diffpatch","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"optional dependency for long text diffing at character level","package":"diff-match-patch","optional":true}],"imports":[{"note":"Named export only; no default export. Since v0.5.0, ESM is used.","wrong":"import DiffPatcher from 'diffpatch'","symbol":"DiffPatcher","correct":"import { DiffPatcher } from 'diffpatch'"},{"note":"Named export for JSON.parse reviver support for Date objects. Works in CommonJS as well.","wrong":"const { dateReviver } = require('diffpatch')","symbol":"dateReviver","correct":"import { dateReviver } from 'diffpatch'"},{"note":"formatters is an object containing html, annotated, etc. Access via formatters.html, etc. ESM-only exports.","wrong":"import { html, annotated } from 'diffpatch'","symbol":"formatters","correct":"import { formatters } from 'diffpatch'"},{"note":"createPatcher was removed in v0.5.0. Use new DiffPatcher() instead.","wrong":"import { createPatcher } from 'diffpatch'","symbol":"createPatcher (deprecated)","correct":"import { DiffPatcher } from 'diffpatch'; const patcher = new DiffPatcher()"}],"quickstart":{"code":"import { DiffPatcher } from 'diffpatch';\n\nconst dp = new DiffPatcher();\n\nconst obj1 = { name: 'Alice', age: 30, items: [1, 2, 3] };\nconst obj2 = { name: 'Bob', age: 30, items: [1, 2, 4] };\n\nconst delta = dp.diff(obj1, obj2);\nconsole.log('Delta:', JSON.stringify(delta, null, 2));\n// {\n//   \"name\": [\"Alice\", \"Bob\"],\n//   \"items\": {\n//     \"_t\": \"a\",\n//     \"2\": [3, 4]\n//   }\n// }\n\n// Patch obj1 to become obj2\ndp.patch(obj1, delta);\nconsole.log('Patched obj1:', obj1);\n\n// Unpatch to revert\ndp.unpatch(obj1, delta);\nconsole.log('Unpatched obj1:', obj1);","lang":"typescript","description":"Basic diff, patch, and unpatch operations with primitive and array values using DiffPatcher."},"warnings":[{"fix":"Replace const { DiffPatcher } = require('diffpatch') with import { DiffPatcher } from 'diffpatch'.","message":"In diffpatch v0.5.0, the library switched from CommonJS to ES modules. If you use require('diffpatch'), you must update to dynamic import or use a bundler that supports ESM.","severity":"breaking","affected_versions":">=0.5.0"},{"fix":"Use import { DiffPatcher } from 'diffpatch' instead of import DiffPatcher from 'diffpatch'.","message":"In diffpatch v0.5.0, the default export was removed. Previously, you could import DiffPatcher as default; now it is a named export only.","severity":"breaking","affected_versions":">=0.5.0"},{"fix":"Use new DiffPatcher() instead of createPatcher().","message":"The createPatcher function was deprecated in v0.4.0 and removed entirely in v0.5.0. Use the new DiffPatcher() constructor.","severity":"deprecated","affected_versions":">=0.5.0"},{"fix":"const dp = new DiffPatcher({ objectHash: obj => obj.id })","message":"When diffing arrays of objects, the default object matching is by position. To match objects by identity, you must provide an objectHash function in the DiffPatcher options. Otherwise, diffs may misinterpret insertions/deletions.","severity":"gotcha","affected_versions":"*"},{"fix":"Use diffpatch both for producing and consuming deltas.","message":"The delta format is not backwards compatible with other diff libraries. Do not mix diffpatch deltas with libraries like jsondiffpatch.","severity":"gotcha","affected_versions":"*"},{"fix":"Upgrade to Node.js >= 8.","message":"When using in Node.js < 8, the library will not work because Node 8+ is required (engines.node >= 8).","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Run 'npm install diffpatch' and ensure import path is 'diffpatch' (not 'diffpatch-master' or similar).","cause":"Package not installed or import path incorrect.","error":"Cannot find module 'diffpatch'"},{"fix":"Replace 'import DiffPatcher from \"diffpatch\"' with 'import { DiffPatcher } from \"diffpatch\"'.","cause":"Using default import but diffpatch only exports named exports since v0.5.0.","error":"Uncaught SyntaxError: The requested module 'diffpatch' does not provide an export named 'default'"},{"fix":"Ensure you have imported { DiffPatcher } and use 'new DiffPatcher()'.","cause":"Using createPatcher (deprecated/removed) or incorrect import.","error":"DiffPatcher is not a constructor"},{"fix":"Verify you created an instance: const dp = new DiffPatcher();","cause":"DiffPatcher instance not created correctly or variable is undefined.","error":"TypeError: Cannot read properties of undefined (reading 'diff')"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}