microsoft / microsoft/TypeScript

Module resolution using nodenext and a wildcard in package.json exports

Open
#55,021 7 comments 26 reactions 1 assignee View on GitHub

@weswigham is already working on this.

Since Jul 24, 2023.

Needs Investigation Rescheduled
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
1d 19h
Merged PRs (30d)
117

Description

Bug Report

🔎 Search Terms

Nodenext wildcard, type cannot be named

🕗 Version & Regression Information

The bug only appears when using nodenext for module resolution

⏯ Playground Link

Cloneable repo: https://github.com/geoffreytools/effect-test-tsc

💻 Code
import { TaggedClass } from '@effect/data/Data';
// import '@effect/data/Equal';

export class Foo extends TaggedClass('Foo')<{}> {}
🙁 Actual behavior
The inferred type of 'Foo' cannot be named without a reference to '../node_modules/@effect/data/Equal'. This is likely not portable. A type annotation is necessary.
🙂 Expected behavior

To compile correctly, without using nodenext it works fine and the same issue doesn't apply to other transitive imports such as Hash that are identically exported. All goes away the very moment there is either an explicit import of Equal or when adding to the library package.json the following:

{
  "exports": {
    "./Equal": {
      "import": {
        "types": "./Equal.d.ts",
        "default": "./mjs/Equal.mjs"
      }
    }
  }
}

Note that the library uses a wildcard ./* as each import map to a file and this is perfectly resolvable by node

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.