svgdotjs / svgdom

Straightforward DOM implementation to make SVG.js run headless on Node.js
MIT License
275 stars 54 forks source link

Probably my configuration, but... #67

Open pragdave opened 4 years ago

pragdave commented 4 years ago

When using svgdom with TypeScript (ts-jest), it fails in module resolution, because main points to a .cjs file. If I change it to reference main-module.js everything works.

As the likely use case is running inside Node anyway, is the .cjs file needed?

Fuzzyma commented 4 years ago

Yes it is needed indeed. Esm modules in node are not widely supported at this point (and with not widely I mean they just were introduced and the support is pretty damn bad). Therefore there is a cjs version which is always picked up as common js module no matter what the package.json says (type: module in our case). However, for node versions which support modules already, there is a new key in the package.json (exports) which resolves explicitely when which file is used.

If typescript is not picking up the correct module it is because the typescript eco system is not up to date with this change. However, cant you just write import {...} from 'svgdom/main_module.js' anyway?

Fuzzyma commented 4 years ago

As a sidenode: Even in the esm version there is at least one file dirname.cjs that is common js. That is because import.meta doesnt work properly yet and i need the dirname