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

Exported types incompatible with ESM when using TypeScript@next #6801

Closed
AndrewLeedham opened this issue Feb 7, 2022 · 5 comments · Fixed by #6802
Closed

Exported types incompatible with ESM when using TypeScript@next #6801

AndrewLeedham opened this issue Feb 7, 2022 · 5 comments · Fixed by #6802

Comments

@AndrewLeedham
Copy link
Contributor

Describe the bug

When importing rxjs in a project using TypeScript@next with the "module": "nodenext" (experimental ESM support) it fails to locate the associated types. As seen in this TypeScript playground: Playground Link.

Expected behavior

TypeScript@next is experimental so I suppose I don't expect it to work. But the API seems fairly stable, so I am raising this issue to track the change. The exports spec defines an optional types field, which if used in rxjs resolved the issue (I have tried this with a patch locally).

Reproduction code

import { Observable, Subject } from 'rxjs';

Reproduction URL

https://www.typescriptlang.org/play?target=99&moduleResolution=99&ts=4.6.0-dev.20220116#code/JYWwDg9gTgLgBAbzgeQEYGcCmUBuBDVAG0wBo4BlAV1QCtMBjeAXzgDMoIQ4ByKADxrpuAbiA

Version

7.4.0

Environment

  • Node.js@16.13.2
  • TypeScript@4.6.0-dev.20220204

Additional context

Related discussion in the TypeScript repo: microsoft/TypeScript#46452 (comment)

@kwonoj
Copy link
Member

kwonoj commented Feb 7, 2022

This is mostly dupe of #4416. We don't offer native esm support in anywhere yet.

@AndrewLeedham
Copy link
Contributor Author

@kwonoj Perhaps the title is misleading. This is more to do with the exports field which rxjs uses, in a node environment this would be CJS, not ESM. The types are therefore also resolved via the exports field, when using this library as CJS but in an ESM enabled project.

@demurgos
Copy link

demurgos commented Feb 9, 2022

Related comment from the TS team.

One of the things we plan to do before shipping this as stable is auditing the top N most popular npm packages that ship their own types and use package.json exports. We’re aware that RxJS needs an update. If you or someone else makes that PR before we get to it, please ping me on it. Thanks!

(cc @andrewbranch)

Also previous issue and MR: #6641 / #6642.

@demurgos
Copy link

@benlesh thank you very much for merging the fix 🙂

Do you know when a new version may be released with it?

@sandrooco
Copy link

@demurgos This was released just yesterday.

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

Successfully merging a pull request may close this issue.

4 participants