svgdotjs / svgdom

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

Trying to use svgdom in Nestjs application but get require() of Es Module not supported Error. #121

Open Mustafa-Aswadi opened 6 months ago

Mustafa-Aswadi commented 6 months ago

I want to use svgdom into nest js application and get the below error Error [ERR_REQUIRE_ESM]: require() of ES Module ..\..\node_modules\svgdom\main-module.js from ..\..\..\main.js not supported. Instead change the require of main-module.js in .\..\..\dist\apps\services\-\main.js to a dynamic import() which is available in all CommonJS modules.

I tested both ways to import the package but did not work.

dendrofen commented 5 months ago

same for me

ManuelPuentes commented 3 months ago

any solution yet?

l86110 commented 3 months ago

tsconfig.json try adding the following config

"ts-node": {
    "compilerOptions": {
      "target": "es2015",
      "module": "commonjs",
      "moduleResolution": "nodenext"
    }
  }

then

const { createSVGWindow } = await import('svgdom')
ManuelPuentes commented 3 months ago

tsconfig.json try adding the following config

"ts-node": {
    "compilerOptions": {
      "target": "es2015",
      "module": "commonjs",
      "moduleResolution": "nodenext"
    }
  }

then

const { createSVGWindow } = await import('svgdom')

hey @l86110 this solution works for me! thank you so much, module option ask me to be set as "nodenext" same as moduleResolution but its working

wariomvc commented 2 weeks ago

I used same solution, but i had other error

tsconfig.json try adding the following config

"ts-node": {
    "compilerOptions": {
      "target": "es2015",
      "module": "commonjs",
      "moduleResolution": "nodenext"
    }
  }

then

const { createSVGWindow } = await import('svgdom')

hey @l86110 this solution works for me! thank you so much, module option ask me to be set as "nodenext" same as moduleResolution but its working

new error

Top-level 'await' expressions are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', or nodenext', and the 'target' option is set to 'es2017' or higher.

some idea to solution