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

Typings resolution error with TS 4.7 in "Node16" mode #1629

Closed
ulrichb opened this issue May 25, 2022 · 3 comments
Closed

Typings resolution error with TS 4.7 in "Node16" mode #1629

ulrichb opened this issue May 25, 2022 · 3 comments

Comments

@ulrichb
Copy link
Contributor

ulrichb commented May 25, 2022

Context

  • Telegraf.js Version: 4.8.2
  • Node.js Version: 16
  • Operating System: Win

Minimal Example Code Reproducing the Issue

import * as telegraf from "telegraf";

With the (as of TS 4.7) released "native Node ESM module" support (activated via"module": "node16") all "telegraf" imports fail with "Could not find a declaration file for module 'telegraf'".

This is because in this mode TSC prefers the "exports" declaration in telegraf's package.json (and ignores the top-level "types": "./typings/index.d.ts"). See this answer from the TS team.

When locally changing "exports": { ".":"./lib/index.js" } to "exports": { ".": { "require": "./lib/index.js", "types": "./typings/index.d.ts" } } the error disappears. This is also documented here: https://www.typescriptlang.org/docs/handbook/esm-node.html

Should I propose a PR with this fix?

@MKRhere
Copy link
Member

MKRhere commented May 29, 2022

Should I propose a PR with this fix?

Yes! PR welcome :)

@ulrichb
Copy link
Contributor Author

ulrichb commented May 30, 2022

Repro sample (used in the following PR): telegraf1629repro.zip

@mees-
Copy link

mees- commented Jun 7, 2022

Telegraf is currently the only library keeping me from fully converting to ESM. I really appreciate the effort! 😁

@MKRhere MKRhere closed this as completed in 6ddc397 Jun 7, 2022
MKRhere added a commit that referenced this issue Jun 7, 2022
Add `types` reference also to the `exports` part to fix #1629
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants