svgdotjs / svgdom

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

Unable to access certain functions - ESM #112

Closed cyberwombat closed 12 months ago

cyberwombat commented 12 months ago

I am trying to use the font functions: setFontDir, setFontFamilyMappings, preloadFonts.

I have tried both 0.1.16 and direct pull of master with same result. Here's what I get with current master:

Screenshot 2023-09-11 at 9 44 47 AM

If I try direct path it works but I get that missing type error (but code works)

import {
  setFontDir,
  setFontFamilyMappings,
  preloadFonts,
  createSVGWindow
} from '../../node_modules/svgdom/main-module.js'

On a side note - why does NPM.js say package is deprecated, dont use etc but no mention at all here?

Thanks!

Fuzzyma commented 12 months ago

The last 2 versions have major bugs. So 0.0.14 should be used atm. I need to release a new one with current changes

Fuzzyma commented 12 months ago

Are you loading it from a module or in a cjs package? I dont have any errors in either case so I am a bit confused. Can you give more context?

cyberwombat commented 12 months ago

My codebase is module (i.e. "type": "module") and typescript. Perhaps an issue with node resolution?

TSConfig

{
  "include": ["./**/*.d.ts", "./**/*.ts", "./**/*.tsx"],
  "compilerOptions": {
    "lib": ["DOM", "DOM.Iterable", "ES2022"],
    "isolatedModules": true,
    "esModuleInterop": true,
    "jsx": "react-jsx",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "module": "ES2022",
    "target": "ES2022",
    "strict": true,
    "allowJs": true,
    "forceConsistentCasingInFileNames": true,
    "skipLibCheck": true,
    "baseUrl": ".",
    "types": ["@shopify/oxygen-workers-types", "@types/node"],
    "paths": {
      "~/*": ["app/*"]
    },
    "noEmit": true
  }
}
Fuzzyma commented 12 months ago

Oh i see, this is a problem with the typings then. Someone recently added svgdom types to definitely typed and they got merged but they are not complete it seems. You probably should open an issue at definitely typed then

cyberwombat commented 12 months ago

thanks yes that's it.