davestewart / alias-hq

The end-to-end solution for configuring, refactoring, maintaining and using path aliases
https://davestewart.co.uk/projects/open-source/alias-hq/
MIT License
333 stars 12 forks source link

Could not find a declaration file for module 'alias-hq'. #75

Open lighth7015 opened 9 months ago

lighth7015 commented 9 months ago

Hi, when trying to use this with a SolidJS project, I'm receiving the following typescript error-

'/node_modules/alias-hq/src/index.js' implicitly has an 'any' type.
  There are types at '/node_modules/alias-hq/types/index.d.ts', but this result could not be resolved when respecting package.json "exports".
The 'alias-hq' library may need to update its package.json or typings.ts(7016)
davestewart commented 7 months ago

Hmm, thanks.

Could you provide a reproduction, or just the code you're using to implement Alias HQ in Solid?

pinge commented 4 months ago

@davestewart you just need to import the package to get this error when using TypeScript (example below with VS Code):

Screen Shot 2024-07-17 at 2 31 51 AM



For types to work properly when using ESM import, you need to remove exports from package.json and add a main property:

diff --git a/node_modules/alias-hq/package.json b/node_modules/alias-hq/package.json
index b9e233a..17c9f15 100644
--- a/node_modules/alias-hq/package.json
+++ b/node_modules/alias-hq/package.json
@@ -3,12 +3,8 @@
   "version": "6.2.3",
   "description": "The end-to-end solution for configuring, refactoring, maintaining and using path aliases",
   "bin": "bin/alias-hq",
-  "exports": {
-    ".": "./src/index.js",
-    "./init": "./src/plugins/module-alias/init.js",
-    "./package.json": "./package.json"
-  },
   "types": "types",
+  "main": "./src/index.js",
   "files": [
     "src/*",
     "cli/*",
npx patch-package alias-hq --exclude 'nothing'

(--exclude 'nothing' is required when patching package.json)

A better solution would be to export and support types for CommonJS and ESM.

You can find a good explanation of what's going on here.