ArtifexSoftware / mupdf.js

JavaScript bindings for MuPDF
https://mupdfjs.readthedocs.io
GNU Affero General Public License v3.0
383 stars 22 forks source link

TypeScript types should work with moduleResolution node #116

Open aldenquimby opened 3 weeks ago

aldenquimby commented 3 weeks ago

I installed mupdf in a TS project and ran into this error:

image

Runtime code works fine, but TypeScript complains.

Adding the following to mupdf/package.json fixes the issue:

  "main": "./dist/mupdf.js",
  "types": "./dist/mupdf.d.ts",
ccxvii commented 3 weeks ago

This error could be because you haven't set the moduleResolution properly.

Did you use the ".mts" suffix on your typescript source file, or did you run the "npm pkg set type=module" command?

If not, please try to do that first.

aldenquimby commented 3 weeks ago

@ccxvii I do have type=module, but I'm using an older moduleResolution. I'll try updating to see if that fixes it!

I see now your docs say nodenext is required. I believe if you add main + types to the package.json, you could drop that requirement, making this a more widely usable library

But in the meantime, I'll see if I can get that resolution working in my project!

aldenquimby commented 3 weeks ago

@ccxvii i confirmed that upgrading my moduleResolution fixed the issue, so feel free to close if you'd like! It's worth noting this was a decent effort, because many older libraries only work with moduleResolution=node. So it may still be nice for you to support the older moduleResolution