What does this library export? How do I import it?
I've tried:
import { createPatch } from "https://unpkg.com/[email protected]/dist/diff.min.js";
which gives me the error:
The requested module 'https://unpkg.com/[email protected]/dist/diff.min.js' does not provide an export named 'createPatch'
I've also tried:
import JsDiff from "https://unpkg.com/[email protected]/dist/diff.min.js";
which gives me the error:
The requested module 'https://unpkg.com/[email protected]/dist/diff.min.js' does not provide an export named 'default'
You can use that in the meantime :
var jsdiff = require('diff')
@jameshfisher Hi, I tried this way and it worked.
import { diffChars } from 'diff';
diffChars('abc', 'adc');
Also, you can try this one:
import * as JsDiff from 'diff';
JsDiff.diffChars('abc', 'adc');
I think the issue is in the export part of the library. You can check it here: https://github.com/kpdecker/jsdiff/blob/master/src/index.js
There is no default export and that's why we cannot import directly.
I would be happy to try to fix this but I have almost no knowledge of the various different JavaScript module/import systems and am pretty unclear on what the desired end state even is, especially since the import syntax shown here doesn't work for anything out of the box. (Am I supposed to be using "type": "module" in package.json and running the script containing the import with --experimental-network-imports? That seems to get me somewhere but I don't know if it matches how @jameshfisher was running his code when he got the error he quotes.)
It'd be helpful to have some examples to play with of minimal projects that try to use some particular import syntax to import stuff from some more popular libraries (like React or Lodash) and succeed, then try to use the same import style to import stuff from jsdiff and fail with an error. I'll still have to educate myself a bunch about module systems, but at least with such examples to work with I'll be able to 1. confirm that what's being asked for is consistent with how other libraries work and therefore reasonable to support and 2. confirm that I've succeeded!
Since I'm not totally sure from the thread above whether jsdiff is even doing anything wrong with regards to exports/imports, I'm gonna close this for now, but will happily reopen and work on a fix if someone spells out exactly what we're doing wrong and shows it's different to other libraries' behaviour, with a reproducible example!