-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Compatibility with old TS libraries under NodeNext resolution #50482
Comments
We are not going to perform invalid resolutions, but I would be open to improving the error message for ESM resolution errors when the target is in node_modules.
Because clearly you didn’t mean anything; the author of the package did. If you or someone else wants to open a PR, I can help with the wording. But the suggestion to just fall back to wrong resolutions is declined. |
Note: In order to show the message By default, it only has the following message and it is a total mystery to the developers. They may don't have the knowledge about all this Node ESM + TypeScript and think "oh, it just not working at all, let's forget it."
To emit the correct declaration resolvable under NodeESM mode, it requires library authors to totally reconfigure their build system and republish the package, and it is even harder if the library author wants to support both CommonJS and ES Module. |
Before we worry about TypeScript resolving types, we need to worry about Node resolving JS. Making a dual CJS/ESM package is harder than making a CJS package. Node’s module support is complicated, even without TypeScript. The nice thing about TypeScript’s approach is once you have everything it takes to satisfy Node, literally all you have to do to satisfy TypeScript is put If |
This comment was marked as outdated.
This comment was marked as outdated.
@a-type two things:
|
I guess for clarity, I’m going to close this rather than retitle it to make it match my verdict of “no, but we’ll update error messages.” I would take a PR for error messages, and @Jack-Works if you want to open another one for that, that’s fine. But I don’t want to leave this open and risk folks thinking there is any possible action we can take that addresses the title of the issue. |
Suggestion
Improve the resolution for old ts libraries.
🔍 Search Terms
NodeNext node_modules
✅ Viability Checklist
My suggestion meets these guidelines:
⭐ Suggestion
Many libraries ships
.d.ts
without.js
extension and mark them astype: "module"
.TypeScript now treat them as error and refuse to resolve the type. This makes it even harder to adopt the new resolution mode.
📃 Motivating Example
Example: https://github.com/Jack-Works/ts-nodenext-legacy-library-resolution
node_modules/invalid-node-esm is a very common pattern in the current ecosystem. TypeScript failed to resolve this package as the following message:
This behavior is correct, but this is not usable.
💻 Use Cases
Improve the compatibility and the adoption of the new resolution mode.
The text was updated successfully, but these errors were encountered: