镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Auto imports not working for modules exported via exports in package.json #46339

Description

@renke

Bug Report

Auto import not working as expected for modules that use the exports field and type: module in package.json.

Relevant PR that introduced exports support: #44501

🕗 Version & Regression Information

Occurs in 4.5.0-dev.20211012 and 4.5.0-beta.

⏯ Playground Link

It's a bit hard to reproduce in the playground, so I've created a repository here https://github.com/renke/typescript-4.5-beta-exports – The README contains some instructions on how to reproduce it. It also describes another bug that was already filed here #46333 so it can probably be ignored.

🙁 Actual behavior

Auto import doesn't work for non-root exported modules (unless they are already imported elsewhere).

Also, ./* exports can not be imported at all.

Running the modules via node works, so the exports configuration should be valid.

🙂 Expected behavior

Auto import should work for all modules explicitly exported via exports when the exporting package is listed in dependencies (as in #38923).

Also, import (and auto import) should work for ./* exports. Unclear if this would lead to performance problems for auto import, but I think this should be supported.

Activity

  1. andrewbranch commented on Oct 13, 2021

    @andrewbranch
    Member

    To clarify, is this a problem only when the importing project is using the new node12 and nodenext module resolution modes, or does this happen even for old modes?

  2. renke commented on Oct 13, 2021

    @renke
    Author

    So my understanding is that module node12 or nodenext (or more specifically the new module resolution it implies) are what actually enables the interpretation of the exports field .

    For old resolutions one has to resort to the types field and a declarations file and deal with the fact that only one (the root?) module is actually available for auto import (although there a few workarounds as used by rxjs and the like). That's what I am doing in the exporter-old package.

    Exposing multiple (sub)modules was not supported prior to the exports support. Exposing all modules (meaning ./* in exports) was not supported at all.

    What usually worked (using the node resolution) is importing a module manually, but with the drawback that one has to specify the exact path to the given module (in my repository one would have to include the lib directory). Of course you can do a few tricks with path mappings, but the burden here is on the consumer which I would like to avoid.

    At least that's my understanding after doing a bit of research in the past. Naturally, I don't know what TypeScript is doing internally.

  3. andrewbranch commented on Jan 24, 2022

    @andrewbranch
    Member

    This should be fixed by #47092

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Needs InvestigationThis issue needs a team member to investigate its status.

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions