Skip to content

Missing documentation for exports alternative paths #58600

Open
@ernestostifano

Description

@ernestostifano

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.

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