Skip to content

ESM "exports" field disables "main" lookup #29932

Closed
@targos

Description

@targos

If there is an "exports" field in the package.json file of a module, the "main" field becomes ignored by the resolver and if one tries to import something from 'package' where there is no '.' export, it throws an error:
Cannot resolve package exports target 'undefined' matched for '.' in /home/mzasso/test/bug-exports/node_modules/my-module/package.json, imported from /home/mzasso/test/bug-exports/test.mjs

Is this the expected behavior? If so, the documentation is not clear about that.

By the way, the exports resolver could probably be improved, saying that there was no matching key instead of trying to use "undefined" as the value.

Repro: https://github.com/targos/bug-esm-exports

@nodejs/modules-active-members

Metadata

Metadata

Assignees

No one assigned

    Labels

    esmIssues and PRs related to the ECMAScript Modules implementation.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions