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.

Error: DiffMatchPatch is not a constructor

See original GitHub issue

Hi all,

I am using angular-diff-match-patch 0.2.4 library with angular 1.5. My project configuration includes typescript and webpack. When I use semantic diff directive, for example:

 <pre semantic-diff left-obj="..." right-obj="..."></pre>

I always receive this exception:

Error: DiffMatchPatch is not a constructor

How can I make it working with webpack?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
yaacovCRcommented, Mar 22, 2018

See https://github.com/amweiss/angular-diff-match-patch/pull/46.

This would streamline above required steps:

  1. Install single required webpack module. Type in the terminal:

    npm install --save-dev expose-loader
    
  2. expose diff-match-patch library in js file:

    require('expose?diff_match_patch!diff-match-patch');
    

    OR via webpack config

        rules: [{
          test: require.resolve('diff-match-patch'),
          use: [{
            loader: 'expose-loader',
            options: 'diff_match_patch'
          }]
        }]
    
1reaction
anotherchrisberrycommented, Aug 10, 2016

Update for @ufoscout - this ended up being how I got around the error:

require('expose?diff_match_patch!diff-match-patch');
let DIFF_INSERT = require('exports?DIFF_INSERT!diff-match-patch/index');
let DIFF_DELETE = require('exports?DIFF_DELETE!diff-match-patch/index');
let DIFF_EQUAL = require('exports?DIFF_EQUAL!diff-match-patch/index');

then, in my service:

$window.DIFF_INSERT = DIFF_INSERT;
$window.DIFF_DELETE = DIFF_DELETE;
$window.DIFF_EQUAL = DIFF_EQUAL;

It’s pretty ugly and I’m sure there’s a better way to do this via Webpack.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using google-diff-match-patch in angular - Stack Overflow
Problem is, how do I import diff_match_patch for this line? var dmp = new diff_match_patch();. javascript · angular · typescript · google-diff- ......
Read more >
diff_match_patch is not a constructor when using react #6225
console error: Uncaught TypeError: diff_match_patch is not a constructor at getDiff (merge.js:649) at DiffView.init (merge.js:53)
Read more >
DiffMatchPatch class - diff_match_patch library - Dart API
Class containing the diff, match and patch methods. Also contains the behaviour settings. Constructors. DiffMatchPatch(). Properties.
Read more >
DiffMatchPatch (netxms-java-components 4.3-SNAPSHOT API)
public class DiffMatchPatch extends Object. Class containing the diff, match and patch methods. Also contains the behaviour settings.
Read more >
How to use the diff-match-patch.diff_match_patch function in diff ...
Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues...
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