diff_match_patch is not a constructor when using react #6225

here is my code:

import diff_match_patch from ‘diff_match_patch’;
import CodeMirror from ‘codemirror’;

window.diff_match_patch = diff_match_patch;

require(‘codemirror/lib/codemirror.css’);
require(‘codemirror/theme/eclipse.css’)
require(‘codemirror/theme/neat.css’)
require(‘codemirror/addon/lint/lint.css’)
require(‘codemirror/addon/merge/merge.css’)
require(‘codemirror/mode/javascript/javascript’)
require(‘codemirror/addon/lint/lint’)
require(‘codemirror/addon/lint/javascript-lint’)
require(‘codemirror/addon/merge/merge’)

let container = document.getElementById(‘mergeArea’);
CodeMirror.MergeView(container, {
origLeft: ‘123’,
origRight: ‘124’,
value: ‘’,
orig: ‘’,
lineNumbers: true,
mode: ‘xml’,
highlightDifferences: true
});

console error:
Uncaught TypeError: diff_match_patch is not a constructor
at getDiff (merge.js:649)
at DiffView.init (merge.js:53)
at new CodeMirror.MergeView (merge.js:571)
at Function.CodeMirror.MergeView (merge.js:537)
at fetchData (index.jsx:64)
at index.jsx:56
at commitHookEffectListMount (react-dom.development.js:19731)
at commitPassiveHookEffects (react-dom.development.js:19769)
at HTMLUnknownElement.callCallback (react-dom.development.js:188)
at Object.invokeGuardedCallbackDev (react-dom.development.js:237)

When i remove ‘window.diff_match_patch = diff_match_patch;’, got 'Uncaught ReferenceError: diff_match_patch is not defined

Yes, for historical reasons (and so that CodeMirror can run without bundling), you’ll need to keep that there.