sindresorhus / p-limit

Run multiple promise-returning & async functions with limited concurrency
MIT License
1.84k stars 99 forks source link

Support lost for Node 16 / CommonJs #63

Closed pp0rtal closed 2 years ago

pp0rtal commented 2 years ago

Hello, I was running p-limit@3 and tried to upgrade to p-limit@4

Reproduce error

➜  test cat package.json 
{
  "dependencies": {
    "p-limit": "^4.0.0"
  }
}

My program is in Typescript and I'm compiling to use CommonJS native ("module": "commonjs", in my tsconfig)

➜  test cat index.js 
const pLimit = require("p-limit")

console.log(pLimit)

resulting to an error at runtime

➜  test node index.js 
/home/portal/test/index.js:1
const pLimit = require("p-limit")
               ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /home/portal/test/node_modules/p-limit/index.js from /home/portal/test/index.js not supported.
Instead change the require of /home/portal/test/node_modules/p-limit/index.js in /home/portal/test/index.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/home/portal/test/index.js:1:16) {
  code: 'ERR_REQUIRE_ESM'
}

With 3.x

program is working

➜  test node .          
[Function: pLimit]

Is the support lost, or am I using the lib wrongly?

pp0rtal commented 2 years ago

Project has became ESM only so we have to stay at 3 major version when using require