Skip to content

Conditional exports doesn't respect alternative paths #37928

@xbaun

Description

@xbaun
  • Version: v14.16.0
  • Platform: Darwin DEV135MAC0211.fritz.box 19.6.0 Darwin Kernel Version 19.6.0: Tue Jan 12 22:13:05 PST 2021; root:xnu-6153.141.16~1/RELEASE_X86_64 x86_64
  • Subsystem:

What steps will reproduce the bug?

When importing a package with conditional exports declared in the package.json, then node doesn't respect alternative path exports:

"exports": {
    "./*": {
        "require": [
            "./dist/cjs/*/index.js",
            "./dist/cjs/*.js"
        ]
    }
}

Node only tries to resolve the first one and fails immediately if the first path to a module doesn't exist. I don't know if this is the intended behaviour, but in the Webpack guide it is explicitly mentioned as a feature (https://webpack.js.org/guides/package-exports/#alternatives).

What is the expected behavior?

Node tries to resolve an import against each entry in the conditional exports array and returns the first successful loaded module.

What do you see instead?

Node only resolves the first entry of the conditional exports alternatives.

Metadata

Metadata

Assignees

No one assigned

    Labels

    moduleIssues and PRs related to the module subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions