Missing documentation for exports alternative paths

Open Beginner friendly
#58,600 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
65/100
Issue type
Documentation
Clarity
Mostly clear
Activity status
Quiet
Tech stack
javascript, nodejs
Domain
documentation

Research direction

Start with the exports section of the packages documentation at nodejs.org/api/packages.html and review the linked Webpack and TypeScript references for the alternative-path behavior. Add a description and practical examples for array-valued export paths, with the documentation clearly explaining when the examples apply.

Written by the indexing model from the issue text.

Description

doc
Affected URL(s)

https://nodejs.org/api/packages.html

Description of the problem

Packages documentation is really helpful to understand motivations and practical usage of exports, from the simplest setup to nested conditions, wildcards, etc. However, it seems to lack a description and examples of "alternative paths" within exports, which I think is really powerful stuff, but currently underrated and not very popular (maybe because of the lack in documentation).

With "alternative paths" what I mean is using arrays as follows:

{
    "exports": {
        ".": {
            "development": {
                "types": "./src/index.ts",
                "import": "./src/index.js",
                "require": "./src/index.cjs",
                "default": "./src/index.cjs"
            },
            "import": {
                "types": "./types/index.d.ts",
                "default": [
                    "./src/index.js",
                    "./esm/index.js"
                ]
            },
            "require": [
                "./src/index.cjs",
                "./cjs/index.cjs"
            ],
            "default": [
                "./src/index.cjs",
                "./cjs/index.cjs"
            ]
        }
    }
}

The only hint I found in the documentation, is string[] syntax under exports.

Beside that, there are some mentions around:

I think that "alternative paths" is the perfect solution for situations like using your own package without having to build it first during development (e.g., TypeScript, transpiling, polyfilling, etc.)

If there is a spec I would love to update the docs myself.

Dominant language
JavaScript
Stars
122k
Forks
37.4k
Avg merge
4d 3h
Merged PRs (30d)
273

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from nodejs/node

All issues in nodejs/node

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.