question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

diff_match_patch is not a constructor when using Require.js

See original GitHub issue

I have a project using Require.js (ver 2.1.18) where I’m using CodeMirror (ver 5.5.1) to view/edit a JavaScript file in the browser (this and all CodeMirror addons work as expected).

I now need to show any diffs in the file, so I’ve been trying to implement the merge.js addon, but having troubles with the diff_match_patch.js lib that is also required.

// Firebug + Firefox 39.0.3
// merge.js
// (line 550, col 12)
"TypeError: diff_match_patch is not a constructor
var dmp = new diff_match_patch();"
// Chrome Version 44.0.2403.130 (64-bit)
// merge.js (551)
"Uncaught TypeError: diff_match_patch is not a function"

I can see that diff_match_patch.js is being loaded by Require, but when passed to that function in merge.js, the JavaScript error breaks the page. The Merge view doesn’t show. Changing the line

var dmp = new diff_match_patch();

to

var dmp = diff_match_patch;

allows the 2 views to render, but the dmp.diff_main map is not created.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
thecerecommented, Nov 1, 2018

Hacking the globals with webpack, works for me:

new webpack.ProvidePlugin({
    diff_match_patch: 'diff-match-patch',
    DIFF_EQUAL: ['diff-match-patch', 'DIFF_EQUAL'],
    DIFF_INSERT: ['diff-match-patch', 'DIFF_INSERT'],
    DIFF_DELETE: ['diff-match-patch', 'DIFF_DELETE'],
}),
0reactions
clintmilnercommented, Aug 16, 2018

@ajinkyasurya I dumped Require.js about a year ago, and I can’t find the commit where I had this + Require.js working. I do know that I was wasn’t importing CodeMirror-related files vai a package.json file. Perhaps try importing manually?

Read more comments on GitHub >

github_iconTop Results From Across the Web

diff_match_patch is not a constructor when using Require.js
I have a project using Require.js (ver 2.1.18) where I'm using CodeMirror (ver 5.5.1) to view/edit a JavaScript file in the browser (this ......
Read more >
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 ...
Read more >
how to fix " is not a constructor" - Stack Overflow
I get a javascript file(such as gds.js), it's published from typescript. So, I have to add a *.d.ts file, when I want to...
Read more >
https://pagure.io/pagure/c/e2f045f42fa71eccec5e432...
highlight.js-internals.js":2}],2:[function(require,module,exports){ +/* + * + ... + if (addPath) { + // No one else is going to attempt to use this value, ......
Read more >
Code coverage report for dist/qunit.js - Trey Hunner
"function" ) { throw new Error( "QUnit logging methods require a callback ... "Member not found" error in IE8 caused by messing with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found