Skip to content

Explain order/precedence for exports-field subpath patterns #44517

@thw0rted

Description

@thw0rted

Affected URL(s)

https://nodejs.org/api/packages.html#subpath-patterns

Description of the problem

The current documentation for subpath patterns gives this example for preventing export of a private path:

// ./node_modules/es-module-package/package.json
{
  "exports": {
    "./features/*.js": "./src/features/*.js",
    "./features/private-internal/*": null
  }
}


//// Consuming code

import featureInternal from 'es-module-package/features/private-internal/m.js';
// Throws: ERR_PACKAGE_PATH_NOT_EXPORTED

This is somewhat confusing in the context of the following section about conditional exports, which says that

Within the "exports" object, key order is significant. During condition matching, earlier entries have higher priority and take precedence over later entries. The general rule is that conditions should be from most specific to least specific in object order.

The documented behavior suggests that conditional matching stops when it finds the first matching entry, while subpath pattern matching reads all paths and somehow chooses one. Does null value (preventing export) override any other matches? What if two paths match and don't have a null value? Should null-value patterns always be specified last? If not, is there a suggested or canonical ordering? The docs should explain this, possibly with more subath-pattern examples.

Metadata

Metadata

Assignees

No one assigned

    Labels

    docIssues and PRs related to the documentations.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions