flitbit / diff

Javascript utility for calculating deep difference, capturing changes, and applying changes across objects; for nodejs and the browser.
MIT License
2.99k stars 213 forks source link

The UMD build is not loadable into JavaScript modules strict mode context e.g. into the Chrome DevTools console #139

Open sompylasar opened 6 years ago

sompylasar commented 6 years ago

I'm trying to use deep-diff in the Chrome DevTools debugger to compare two objects while sitting paused on a breakpoint, for that I'm trying to use import() to load deep-diff into the page to use it later via a global variable when paused.

To reproduce the failure to load, try running this in Chrome DevTools console (Chrome 67):

import('https://unpkg.com/deep-diff@1.0.1/index.js').then((module) => { console.log(module) })

Actual:

Uncaught (in promise) TypeError: Cannot set property 'DeepDiff' of undefined
    at index.js:521
    at index.js:2
    at index.js:23

Expected: it loads fine and prints the module exports.

Here's what needs to change in the UMD wrapper:

- }(this, function (root) {
+ }(typeof self !== 'undefined' ? self : this, function (root) {

Related: https://github.com/umdjs/umd/pull/124 https://github.com/umdjs/umd/pull/125