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

Package cannot be imported in TS project compiled with NodeNext #173

Closed
Josh-Cena opened this issue Jun 9, 2022 · 2 comments
Closed

Package cannot be imported in TS project compiled with NodeNext #173

Josh-Cena opened this issue Jun 9, 2022 · 2 comments
Labels
help wanted Extra attention is needed

Comments

@Josh-Cena
Copy link

While working on facebook/docusaurus#7586, eta was one of the packages blocking a successful compilation.

To Reproduce

yarn add typescript eta

tsconfig.json:

{
  "compilerOptions": {
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "strict": true
  }
}

Add a TS file with:

import eta from "eta";

It errors: "Could not find a declaration file for module 'eta'. 'node_modules/eta/dist/eta.cjs' implicitly has an 'any' type."

The reason is because eta's package.json exports does not have a types field for each entry, so TS can't associate the js files with their types. (Before, TS would always use the root types entry).

Fixing this is a bit involved, because the package also has "type": "module", which causes the .d.ts files to be interpreted as ESM. Therefore, even for .d.ts files, explicit extensions are required. I'm not sure what the best way to fix this is, so I just want it to be in your backlog first.

Expected behavior

Successful TS compilation

Package & Environment Details

  • Environment: Node 18.3.0
  • Version: 1.12.3

Additional context

There's some basic writeup here: https://devblogs.microsoft.com/typescript/announcing-typescript-4-7/#package-json-exports-imports-and-self-referencing I can't find a more comprehensive guide.

@nebrelbug
Copy link
Collaborator

@jakubmazanec just added a "types" field to the exports entry in package.json, but I'll leave this open because the exports field needs some more substantial changes.

@nebrelbug
Copy link
Collaborator

@Josh-Cena this should be working now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants