delvedor / hpagent

A ready to use http and https agent for working with proxies that keeps connections alive!
MIT License
182 stars 36 forks source link

ESM / moduleResolution node16 support #94

Closed Maxim-Mazurok closed 2 years ago

Maxim-Mazurok commented 2 years ago

As suggested in https://github.com/sindresorhus/got/issues/2051#issuecomment-1259401339 I changed my moduleResolution to be node16. And I get this error:

src/utils.ts:4:47 - error TS7016: Could not find a declaration file for module 'hpagent'. '/home/maxim/google-api-typings-generator/node_modules/hpagent/index.mjs' implicitly has an 'any' type.
  Try `npm i --save-dev @types/hpagent` if it exists or add a new declaration (.d.ts) file containing `declare module 'hpagent';`

4 import {HttpProxyAgent, HttpsProxyAgent} from 'hpagent';

Project: https://github.com/Maxim-Mazurok/google-api-typings-generator/blob/master/src/utils.ts#L4

Workaround:

  1. Change exports in hpagent/package.json to be "exports": "./index.js",
  2. Use patch-package: npx patch-package hpagent --exclude 'nothing'

Patch:

TODO: Remove this after this is fixed: https://github.com/delvedor/hpagent/issues/94
diff --git a/node_modules/hpagent/package.json b/node_modules/hpagent/package.json
index b9800c2..44c7f8c 100644
--- a/node_modules/hpagent/package.json
+++ b/node_modules/hpagent/package.json
@@ -4,13 +4,7 @@
   "description": "A ready to use http and https agent for working with proxies that keeps connections alive!",
   "main": "index.js",
   "types": "index.d.ts",
-  "exports": {
-    ".": {
-      "require": "./index.js",
-      "import": "./index.mjs"
-    },
-    "./*": "./*.js"
-  },
+  "exports": "./index.js",
   "scripts": {
     "test": "standard && NODE_EXTRA_CA_CERTS=test/fixtures/certs_unit_test.pem ava -v test/*.test.js && tsd",
     "test-ci": "standard && ava -v test/*.test.js && tsd"
ruckonic commented 2 years ago

fixed with pr #95