#How to Load ES Modules

13 messages · Page 1 of 1 (latest)

drifting musk
#

My Nest App depends on a few custom ES Module libraries that I wrote. However, when I run my app, it is saying Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /Users/patrickluy/Documents/Business/Perivel/Products/perivel.com/node_modules/@swindle/core/dist/index.js require() of ES modules is not supported.

So far, I have tried setting "type": "module" in my package.json file. But, that didn't work. How do I fix this error?

green prairie
#

that's it

drifting musk
#

So, I have to use await import(“my module”)?

Hmm. Let me see.

tame hound
#

Hello everyone.

Recenlty, a lot of new packages keep going to be ESM only package. which causes problems of using it inside a nest.js project based on common.js.

I'm lost with one of this package, trying to import inside a nest.js project.

This is a detailed notion project how I get the errors and my tries to find a solution.

https://ribbon-empress-fbc.notion.site/use-ESM-only-package-inside-nest-js-project-1c5ad00515c643429afaa334bafefee4

I activate chat in Notion doc, or we can continue the chat here in discord .
I need your help for this, thankies

Ayoub's Notion on Notion

Hello everyone , I hope that your doing well.

upbeat whale
#

Hey @tame hound, please don't DM me trying to get my attention on this. micalevisk has already pointed out how you can import ESM packages in a CJS context. If you're having any more specific trouble, you'll need to be detailed in what's being problematic

tame hound
#

Hey @upbeat whale , Thanks for your answer. I tried the @green prairie solution, but give an error. I detailed all my tries and the errors inside the Notion doc.

upbeat whale
#

Got a minimum reproduction that shows this? If I recall, there's an option you can add to the tsconfig that makes it not auto-transpile the import to a require. Someone recently made a PR to #826157674554064946 to allow for esm imports ofplugns

#

compilerOptions.moduleResolution: "Node16"

tame hound
#

This work perfectly. Thanks @upbeat whale for your help.

#

I add an update to the notion doc, and remarked as resolved.