sindresorhus / p-limit

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

Cannot find package 'async_hooks' imported from p-limit #84

Closed jpshack-at-palomar closed 6 days ago

jpshack-at-palomar commented 2 weeks ago

node v20.14.0 typescript 5.5.2 p-limit 5.0.0

No bundlers in use.

npm install 
Exception during run: Error: Cannot find package 'async_hooks' imported from /my-project/node_modules/p-limit/package.json
    at packageResolve (/my-project/node_modules/ts-node/dist-raw/node-internal-modules-esm-resolve.js:757:9)
    at resolvePackageTargetString (/my-project/node_modules/ts-node/dist-raw/node-internal-modules-esm-resolve.js:424:16)
    at resolvePackageTarget (/my-project/node_modules/ts-node/dist-raw/node-internal-modules-esm-resolve.js:464:12)
    at resolvePackageTarget (/my-project/node_modules/ts-node/dist-raw/node-internal-modules-esm-resolve.js:510:26)
    at packageImportsResolve (/my-project/node_modules/ts-node/dist-raw/node-internal-modules-esm-resolve.js:620:26)
    at moduleResolve (/my-project/node_modules/ts-node/dist-raw/node-internal-modules-esm-resolve.js:793:21)
    at Object.defaultResolve (/my-project/node_modules/ts-node/dist-raw/node-internal-modules-esm-resolve.js:912:11)
    at /my-project/node_modules/ts-node/src/esm.ts:218:35
    at entrypointFallback (/my-project/node_modules/ts-node/src/esm.ts:168:34)
    at /my-project/node_modules/ts-node/src/esm.ts:217:14

tsconfig.json:

{
  "compilerOptions": {
    "sourceMap": true,
    "declaration": true,
    "lib": ["ES2022"],
    "module": "NodeNext",
    "outDir": "dist",
    "rootDir": "src",
    "strict": true,
    "target": "ES2022",
    "moduleResolution": "NodeNext",
    "noEmit": false,
    "composite": true,
    "pretty": true,
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true
  },
  "include": ["src/**/*"],
  "ts-node": {
    "esm": true
  }
}

I see https://github.com/sindresorhus/p-limit/issues/72 but it appears to have been closed and locked without the issue having been bottomed out for ESM / typescript.

Pointers greatly appreciated.

crypt0miester commented 1 week ago

hello, using patch-package you can do the following:

diff --git a/node_modules/p-limit/index.js b/node_modules/p-limit/index.js
-import {AsyncResource} from '#async_hooks';
+import {AsyncResource} from './async-hooks-stub';

the dev for some reason seem to not want to change it.

sindresorhus commented 6 days ago

The latest version no longer uses subpath exports: https://github.com/sindresorhus/p-limit/releases/tag/v6.0.0