Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Mustafa-Aswadi opened this issue Mar 11, 2024 · 5 comments

Comments

@Mustafa-Aswadi
Copy link

Mustafa-Aswadi commented Mar 11, 2024

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
Copy link

same for me

@ManuelPuentes
Copy link

any solution yet?

@l86110
Copy link

l86110 commented May 29, 2024

tsconfig.json try adding the following config

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

then

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

@ManuelPuentes
Copy link

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants