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:
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
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
```
(async () => {
const { Novu } = await import("@novu/node");
const novu = new Novu("YOUR_SECRET_KEY");
})();
```
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 () => {
const { Novu } = await import("@novu/node");
const novu = new Novu("YOUR_SECRET_KEY");
})();
```
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.
@Jay
Just want to follow up here
Thanks @Pawan Jain I will try this!
@Jay
Did you get chance to try
@novu/api
sdk@Pawan Jain Not yet, will try it soon and let you know!
Sure, keep us updated 🙌🏻
@Pawan Jain This worked great! Thank you so much!
@Jay, you just advanced to level 1!
Thanks for the update Jay