jsondiffpatch icon indicating copy to clipboard operation
jsondiffpatch copied to clipboard

Missing formatters when using AMD in browser

Open donnielrt opened this issue 10 years ago • 6 comments

The jsondiffpatch.formatters object doesn't seem to get set when using jsondiffpatch (with require.js). Seems like this might the culprit:

https://github.com/benjamine/jsondiffpatch/blob/master/src/main.js#L52

We don't seem to be attaching the formatters for the browser. I've confirmed that adding them in there makes the formatter available.

donnielrt avatar Apr 28 '15 00:04 donnielrt

I think I have the same issue with Browserify. The formatters are not set for the same reason

mparpaillon avatar May 15 '15 13:05 mparpaillon

I guess I never tried this using AMD, on the Demo page you can see I just included them after the main bundle, and you can see by looking at that page sources that they get attached automatically.

I'm not sure there's a simple way to make both files support AMD, maybe because they use CommonJS internally, so in a browser the require function is redefined by Browserify.

So, in theory, if you load both files in order (first jsondiffpatch.min.js and then jsondiffpatch.formatters.min.js) and prevent require.js (if that's the loader you're using) from removing jsondiffpatch global, this should just work.

Finally there might a simpler solution which is loading the "full" bundle available at: https://github.com/benjamine/jsondiffpatch/tree/master/public/build that bundle includes the builtin formatters (and google diffmatchpatch lib for text diffing)

benjamine avatar Jun 16 '15 21:06 benjamine

@benjamine I seem to recall encountering this with the full bundle as well

donnielrt avatar Jun 18 '15 22:06 donnielrt

@benjamine, I can confirm that including the full bundle doesn't make formatters available as well.

grushetsky avatar May 14 '16 12:05 grushetsky

you can check the demo page, http://benjamine.github.io/jsondiffpatch/demo/index.html which uses all formatters (in the tabs at the bottom), that page has this on the head:

  <script type='text/javascript' src='../build/jsondiffpatch.min.js'>
  </script>
  <script type='text/javascript' src='../build/jsondiffpatch-formatters.min.js'>
  </script>

can you guys provide an example to reproduce this issue?

benjamine avatar Jun 06 '16 22:06 benjamine

why not integrate formatters into main,so we can import and use it smoothly after npm install.

npm install jsondiffpatch

then use it in es6 way with webpack

import jsondiffpatch from 'jsondiffpatch'

hiwanz avatar Aug 29 '17 06:08 hiwanz

I believe formatters are now available through the main bundle. I'm going to close this issue, let me know if there are still remaining issues with the current solution.

Methuselah96 avatar Aug 26 '23 19:08 Methuselah96