-
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
TypeScript module "Node16" does not resolve types of CJS module #49160
Comments
To expand on this, TypeScript 4.7.1-rc with https://github.com/scott-lc/tsc-nodenext
With
Setting |
Unfortunately in the Seeing that colors has not been updated in 3 years but still gets 21M downloads a week means that a lot of developers are going to run into this issue. Should the TypeScript compiler support this use case or is it going to be up to the Node/NPM community to update existing packages that don't exactly conform to the |
I've also declaration reference issues for external CommonJS packages after switching to Namely Can also reproduce @LaurensRietveld's issue with Other CommonJS packages with inline declarations (e.g. |
Thanks @ulrichb
|
Every one of the packages mentioned here is misconfigured. You already figured out the issue with colors. (Actually, I’m a little surprised that colors even works with While node16/nodenext was in preview over the last two releases, we made an effort to track down some of the most popular npm packages that have TypeScript typings and package.json |
Thanks Andrew, I get the rationale and the choice not to support incorrect metadata. The effect is a pity though, considering some packages (such as the colors package for known reasons) are not expected to be actively maintained. |
A note for those using the colors package with yarn2+: the yarn patch functionality also works on package.json files. Depending on your usecase, this may be a way out when using dependencies like colors |
@LaurensRietveld Shouldn't we reopen this issue until the universe (including colors) gets migrated? |
I just ran into this with [email protected] and [email protected] I'd actually disagree with @andrewbranch's statement at #49160 (comment) . I think projects like errlop and commander were properly specified at the time they released those specific versions. Without the ability in open-source to migrate all packages that specify types, this is probably going to continue to be painful until a fallback is added that works with the current state of the world |
(Commander was updated in v9.2.0 with support for the new resolution approach.) |
I didn’t say they were always misconfigured, but they’re misconfigured now 🤷. They opted to use package.json Also, this is not known widely enough: all any package author has to do is put their |
But I also want to make sure that we have empathy for why people were using exports already. It seems to be the only way to support commonjs and esm in the same package. And I can see how it super desirable to make it easier for your package to be used in both node and the browser. And I also think relying on the layout of where the .d.ts file is relative to the .js would lead to bloat/repetitiveness if you you’re trying to support both in the same package. |
The concept of "misconfigured" is preposterous given that there is no standard for So the idea that something in package.json is "misconfigured" because it's old is simply wrong. If it worked before, then it's not misconfigured. An ecosystem tool has just chosen to break them. After 10+ years in the Node scene the package.json nightmare has only gotten worse. I'm not sure what the solution is, but the fact is that |
This is not a bug with the TypeScript compiler but a "feature"... See microsoft/TypeScript#49160 See ajv-validator/ajv#2047
Bug Report
🔎 Search Terms
NodeNext, esm, CJS, colors
🕗 Version & Regression Information
⏯ Playground Link
I didn't include a playground link, as I can't reference dependencies there.
See here for an MWE.
To test:
💻 Code
🙁 Actual behavior
TypeScript cannot find the typings for some CommonJS packages such as colors and form-data-encoder
As a result, I'm getting this error:
🙂 Expected behavior
ESM module behaviour to import CJS as it used to.
Related
#47848
The text was updated successfully, but these errors were encountered: