Error [ERR_REQUIRE_ESM]: require() of ES Module when using retry-axios

513 Views Asked by At
const rax = require('retry-axios');

Error [ERR_REQUIRE_ESM]: require() of ES Module

I was trying to implement a retry mechanism with retry-axios. After installing the package I got the Error [ERR_REQUIRE_ESM]: require() of ES Module error. I’m not too sure what this ESM is, I’ve never dealt with it before, therefore I don’t know what to do to fix this.

1

There are 1 best solutions below

0
Pop Todi On

There're 2 main syntax of JS

  1. CJS - CommonJS (using const ... = require() )
  2. ESM - ES Module (using import ... from "" )

Some library supports only one syntax, some supports both. You can check library's main syntax from package.json if there's field "type": "module" it means it supports only ESM syntax You may need to use some alternative library