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

Missing types in typescript with module resolution nodenext #385

Closed
ZachHaber opened this issue Jan 31, 2023 · 3 comments · Fixed by #389
Closed

Missing types in typescript with module resolution nodenext #385

ZachHaber opened this issue Jan 31, 2023 · 3 comments · Fixed by #389
Labels
bug Bug or defect types TypeScript type definitions
Milestone

Comments

@ZachHaber
Copy link

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch @hapi/hoek@11.0.2 for the project I'm working on.

I'm using typescript with the config "module": "NodeNext", which makes typescript very particular about the exports and types. Due to this, when I updated @hapi/hoek to the latest version (11.0.2) from version ^10, I started getting an error that I was missing the types for @hapi/hoek despite the types being in the package. This error is fixed by adding the index.d.ts type file to the main exports types field.

Then in the project you have to pull in Hoek as either individual named exports or using import * as Hoek from '@hapi/hoek'

Here is the diff that solved my problem:

diff --git a/node_modules/@hapi/hoek/package.json b/node_modules/@hapi/hoek/package.json
index ce58817..4436342 100644
--- a/node_modules/@hapi/hoek/package.json
+++ b/node_modules/@hapi/hoek/package.json
@@ -8,7 +8,8 @@
   "exports": {
     ".": {
       "import": "./lib/index.mjs",
-      "require": "./lib/index.js"
+      "require": "./lib/index.js",
+      "types": "./lib/index.d.ts"
     },
     "./applyToDefaults": "./lib/applyToDefaults.js",
     "./assert": "./lib/assert.js",

This issue body was partially generated by patch-package.

@kanongil
Copy link
Contributor

I haven’t looked at your proposed solution, but I can confirm the issue.

@kanongil kanongil added the types TypeScript type definitions label Jan 31, 2023
@ZachHaber
Copy link
Author

If anyone else is having this issue in the meantime, instead of using patch-package, you can also import the sub-modules directly (which does use commonjs, but the interop doesn't have an issue here)
e.g.

import clone from '@hapi/hoek/clone'

It's a little more annoying and doesn't have the auto-import functionality that the main import does, but it won't cause type issues.

@Nargonath Nargonath linked a pull request Dec 5, 2023 that will close this issue
@Nargonath Nargonath added the bug Bug or defect label Dec 5, 2023
@Nargonath Nargonath added this to the 11.0.4 milestone Dec 5, 2023
@Nargonath
Copy link
Member

Nargonath commented Dec 5, 2023

Fix published in v11.0.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug or defect types TypeScript type definitions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants