Skip to content

Clarify Invalid Path Segment Rules in exports Field Documentation #58576

@algoORgoal

Description

@algoORgoal

Affected URL(s)

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

Description of the problem

Hello Node.js documentation team,

I would like to request an update or addition to the Packages documentation, specifically the "Subpath Exports" section, to clearly explain the rules regarding invalid path segments in the exports field of package.json.

Background

Currently, the documentation states that all paths in "exports" must be relative file URLs starting with ./. However, it does not explicitly mention that certain path segments—such as .. (parent directory), . (current directory), and their URL-encoded equivalents—are forbidden within export targets. This rule is enforced by Node.js and is critical for package authors to understand, as using these segments will cause runtime errors or warnings.

Why this matters

  • Many package authors like msw and users are unaware that targets like "./../lib/index.js" are invalid and will not work.
  • The Node.js resolver enforces this rule strictly, but the documentation does not make it obvious.
  • This leads to confusion, unexpected errors, and wasted debugging time.

What I'm requesting

  • A dedicated section or callout in the "Subpath Exports" documentation that:
    • Clearly lists which path segments are forbidden (e.g., .., ., node_modules, and their URL-encoded forms).
    • Explains the rationale (to prevent escaping the package boundary and ensure encapsulation).
    • Provides examples of both valid and invalid exports targets.
    • Optionally, references the relevant part of the Node.js source code or spec for advanced users.
    • If maintainers are willing to receive any contribution regarding this, I can work on this.

Example

Invalid path segments in exports targets

The target of an export subpath must not contain any segment that is .., ., node_modules, or their URL-encoded equivalents. For example, "./../lib/index.js" is invalid and will cause an error.
the entire regex representation of invalid path segments: const invalidSegmentRegEx = /(^|\\|\/)((\.|%2e)(\.|%2e)?|(n|%6e|%4e)(o|%6f|%4f)(d|%64|%44)(e|%65|%45)(_|%5f)(m|%6d|%4d)(o|%6f|%4f)(d|%64|%44)(u|%75|%55)(l|%6c|%4c)(e|%65|%45)(s|%73|%53))?(\\|\/|$)/i;

References

Thank you for your work on Node.js and its documentation!
This clarification would help package authors and users avoid common pitfalls and improve compatibility across the ecosystem.

Activity

added
docIssues and PRs related to the documentations.
on Jun 4, 2025
changed the title [-]Clarify Invalid Path Segment Rules in `exports` Field Documentation[/-] [+][docs] Clarify Invalid Path Segment Rules in `exports` Field Documentation[/+] on Jun 4, 2025
changed the title [-][docs] Clarify Invalid Path Segment Rules in `exports` Field Documentation[/-] [+]Clarify Invalid Path Segment Rules in `exports` Field Documentation[/+] on Jun 4, 2025
marco-ippolito

marco-ippolito commented on Jun 5, 2025

@marco-ippolito
Member

Would you like to send a PR?

0hmX

0hmX commented on Jun 6, 2025

@0hmX
Contributor

@marco-ippolito @algoORgoal lmk your thoughts on the PR. I did what I thought was best by adding a new section rather than editing the "subpath-exports"

I reviewed the resolution logic, and I have addressed the two major cases that people should be aware of. If I missed anything, lmk.

algoORgoal

algoORgoal commented on Jun 7, 2025

@algoORgoal
Author

@marco-ippolito @algoORgoal lmk your thoughts on the PR. I did what I thought was best by adding a new section rather than editing the "subpath-exports"

I reviewed the resolution logic, and I have addressed the two major cases that people should be aware of. If I missed anything, lmk.

This looks really concise to me!

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

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

      Participants

      @algoORgoal@marco-ippolito@0hmX

      Issue actions

        Clarify Invalid Path Segment Rules in `exports` Field Documentation · Issue #58576 · nodejs/node