Loading CJS modules through an ES module library #16616
Replies: 2 comments 1 reply
-
I've been working on this further, and it looks like moving these dependencies to So, if I have a If anyone can share what the recommended setup is in this use case, I would love to know. |
Beta Was this translation helpful? Give feedback.
-
@jerryjappinen I know this is an old discussion, but were you ever able to get some clarity around this? I have a similar question. |
Beta Was this translation helpful? Give feedback.
-
I have a utility library that I use for multiple Nuxt 3 apps.
"type": "module"
in itspackage.json
This utility library has many dependencies written in CJS which cause an error when loaded in my Nuxt app. These dependencies work when I load them in a Nuxt app directly, but when referenced in the utility library, they get loaded differently and throw errors. Nuxt transpiles my code as ESM but fails when a dependency is written in CJS, even though they are different packages.
Example libraries include
contentful.js
andgraphql-request
(so pretty common and widely used libraries that are beyond my reach to make changes in, at least in the near future).With Nuxt 3's automagic ES/CJS module loading logic, what would be the recommended way to deal with this scenario?
Beta Was this translation helpful? Give feedback.
All reactions