-
Notifications
You must be signed in to change notification settings - Fork 654
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
Fix errors with loading type declaration files when TypeScript module resolution is set to Node16
or NodeNext
#999
Fix errors with loading type declaration files when TypeScript module resolution is set to Node16
or NodeNext
#999
Conversation
misspelled word.
pronounciation -> pronunciation
…ts` file references, to fix TS import errors
When I tried to import |
Node16
or NodeNext
…s earlier than 4.5
After some consultation with Bing chat, I realized the top-level // package.json
{
"name": "my-package",
"type": "module",
"exports": {
".": {
// Entry-point for `import "my-package"` in ESM
"import": "./esm/index.js",
// Entry-point for `require("my-package") in CJS
"require": "./commonjs/index.cjs",
// Entry-point for TypeScript resolution
"types": "./types/index.d.ts"
},
},
// CJS fall-back for older versions of Node.js
"main": "./commonjs/index.cjs",
// Fall-back for older versions of TypeScript <--- Note
"types": "./types/index.d.ts"
} The original "typesVersions": {
"*": {
"one": [
"types/one.d.ts"
],
"two": [
"types/two.d.ts"
],
"three": [
"types/three.d.ts"
]
}
}, I looked up the documentation but I still don't know if it does anything with regards to multiple exports? I'll bring it back if needed, though I'm not sure if it had any effects. Edit: I brought |
…mpatibility for old TS versions, although it is not needed on TypeScript 4.5+, and may not be 100% effective.
hey Rotem - thank you so much for this. Yes- I've heard that this I've never felt that changing typescript is a major change - but yeah, people may complain, so we should do this carefully. |
changed my mind - LGTM. May bug you w/ some questions before next release. |
The most significant error is:
Here is a relevant issue on the TypeScript repository (closed as "external")
Solution that seems to work:
In
package.json
I specified thetypes
property for each individual export (with relative path):However, this didn't completely fix all the errors.
Another problem is that some definition files have
.ts
extensions, so I renamed the extensions of those files to.d.ts
.Another issue is that the internal reference in the definition files didn't include the full
.d.ts
extensions so I got errors like:So I changed references like
to:
I'm not sure if these changes are 100% backwards-compatible, since I renamed
.ts
files to.d.ts
files (I don't know why they had the.ts
extension).Also, I'm not sure how these changes would be compatible with older versions of TypeScript and node.js.(edit: I tried to make it backwards-compatible in further changes).I decided to suggest this as a pull request, rather than an issue, because I already made these changes on my local copy of the library, and I wanted this to be resolved fast, to enable easy updates to future versions of the package. Please suggest or make any further changes you feel are needed.