N
Novu3mo ago
Jay

ERR_REQUIRE_ESM axios error with @novu/node package

I'm using v2.0.6 of the @novu/node package in my express application and when I run the novu.trigger() command, I get the following error:
/Projects/dashboard/node_modules/@novu/node/build/main/lib/novu.js:1
Error [ERR_REQUIRE_ESM]: require() of ES Module /Projects/dashboard/node_modules/@novu/node/node_modules/axios/index.js not supported.
Instead change the require of index.js in null to a dynamic import() which is available in all CommonJS modules.
at Object.<anonymous> (/Projects/dashboard/node_modules/@novu/node/build/main/lib/novu.js:49:31) {
code: 'ERR_REQUIRE_ESM'
}
/Projects/dashboard/node_modules/@novu/node/build/main/lib/novu.js:1
Error [ERR_REQUIRE_ESM]: require() of ES Module /Projects/dashboard/node_modules/@novu/node/node_modules/axios/index.js not supported.
Instead change the require of index.js in null to a dynamic import() which is available in all CommonJS modules.
at Object.<anonymous> (/Projects/dashboard/node_modules/@novu/node/build/main/lib/novu.js:49:31) {
code: 'ERR_REQUIRE_ESM'
}
I've worked around this by creating a proxy wrapper around Novu to handle the axios import but is there any better solution? I'm on node v20.15.1
11 Replies
Pawan Jain
Pawan Jain3mo ago
Hi Jay

If your application is in CJS (Common JS), then there are 2 options - Convert CJS application to ESM by adding { "type": "module" } in package.json and changing require statement to import statements - Use Dynamic Import for @novu/node
```
(async () =&gt; {
const { Novu } = await import("@novu/node");
const novu = new Novu("YOUR_SECRET_KEY");
})();
```
Jay
JayOP3mo ago
Thanks @Pawan Jain . My application is ESM, and the issue seems to be how axios (which is a subdependency of @novu/node) is being imported into the @novu/node app. It's being imported with require() but that's not supported by that version of axios. I tried overriding the version of the axios subdependency to a version that supports require, but that seemed to break the app.
Pawan Jain
Pawan Jain3mo ago
@jay

We recently launched new nodejs sdk, can you try this one?
https://github.com/novuhq/novu-ts
Pawan Jain
Pawan Jain2mo ago
@Jay Just want to follow up here
Jay
JayOP2mo ago
Thanks @Pawan Jain I will try this!
Pawan Jain
Pawan Jain2mo ago
@Jay Did you get chance to try @novu/api sdk
Jay
JayOP2mo ago
@Pawan Jain Not yet, will try it soon and let you know!
Pawan Jain
Pawan Jain2mo ago
Sure, keep us updated 🙌🏻
Jay
JayOP2mo ago
@Pawan Jain This worked great! Thank you so much!
Novu_Bot
Novu_Bot2mo ago
@Jay, you just advanced to level 1!
Pawan Jain
Pawan Jain2mo ago
Thanks for the update Jay

Did you find this page helpful?