Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript types not resolving when using tsconfig with moduleResolution: "Bundler" #191

Open
jrouleau opened this issue Jan 1, 2024 · 3 comments · May be fixed by #192 or #193
Open

Typescript types not resolving when using tsconfig with moduleResolution: "Bundler" #191

jrouleau opened this issue Jan 1, 2024 · 3 comments · May be fixed by #192 or #193

Comments

@jrouleau
Copy link

jrouleau commented Jan 1, 2024

Could not find a declaration file for module 'tinykeys'. './node_modules/tinykeys/dist/tinykeys.module.js' implicitly has an 'any' type.
  There are types at './node_modules/tinykeys/dist/tinykeys.d.ts', but this result could not be resolved when respecting package.json "exports". The 'tinykeys' library may need to update its package.json or typings.ts(7016)

Here's what I found while researching this issue:
microsoft/TypeScript#52363
https://arethetypeswrong.github.io/?p=tinykeys%402.1.0
https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/UntypedResolution.md
https://stackoverflow.com/questions/72457791/typescript-packages-that-ship-with-mjs-and-d-ts-but-without-d-mts-how-to-i

@jrouleau jrouleau linked a pull request Jan 1, 2024 that will close this issue
@jgoz jgoz linked a pull request Mar 9, 2024 that will close this issue
@KittyGiraudel
Copy link

Perhaps somewhat related, types also cannot be resolved when using "moduleResolution": "node" apparently.

Could not find a declaration file for module 'tinykeys'. '/path/to/node_modules/tinykeys/dist/tinykeys.module.js' implicitly has an 'any' type.
There are types at '/path/to/node_modules/tinykeys/dist/tinykeys.d.ts', but this result could not be resolved under your current 'moduleResolution' setting. Consider updating to 'node16', 'nodenext', or 'bundler'.ts(7016)

@typhonrt
Copy link

typhonrt commented Oct 1, 2024

Needs types entry in exports:

{
  "exports": {
    ".": {
      "types": "./dist/tinykeys.d.ts",
      "import": "./dist/tinykeys.module.js",
      "require": "./dist/tinykeys.js"
    }
  }
}

OK.. Saw the 2nd PR which got it right.. Currently using a fork just for this.

@jrouleau
Copy link
Author

FYI, you can patch this locally with patch-package

Note: changes to package.json files are excluded by default so use --exclude 'nothing' when creating the patch. E.g. npx patch-package tinykeys --exclude 'nothing'

Here's our patches/tinykeys+3.0.0.patch file:

diff --git a/node_modules/tinykeys/package.json b/node_modules/tinykeys/package.json
index bbda4b2..38fc5a5 100644
--- a/node_modules/tinykeys/package.json
+++ b/node_modules/tinykeys/package.json
@@ -16,7 +16,8 @@
   "exports": {
     ".": {
       "import": "./dist/tinykeys.module.js",
-      "require": "./dist/tinykeys.js"
+      "require": "./dist/tinykeys.js",
+      "types": "./dist/tinykeys.d.ts"
     }
   },
   "keywords": [

And a sample package.json:

{
  "scripts": {
    "postinstall": "patch-package"
  },
  "dependencies": {
    "patch-package": "^8.0.0",
    "tinykeys": "^3.0.0"
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants