Skip to content

feature: allow usage of both "exports" and non-"exports" resolution #51626

Closed as not planned
@llllvvuu

Description

@llllvvuu

What is the problem this feature will solve?

(summary from vercel/next.js#50357 (comment))

In a project that exports many vendored packages, it is not feasible to copy every "main" from each vendored package to the "exports" map. But it is desirable to map some exports, such as: 'next/link' -> ./link.js

We are not able to do this, due to:

preventing any other entry points besides those defined in "exports"

Existing packages introducing the "exports" field will prevent consumers of the package from using any entry points that are not defined, including the package.json (e.g. require('your-package/package.json')). This will likely be a breaking change.

The following advice is not feasible in the situation mentioned above:

To make the introduction of "exports" non-breaking, ensure that every previously supported entry point is exported. It is best to explicitly specify entry points so that the package's public API is well-defined.

What is the feature you are proposing to solve the problem?

* Allow putting something like:

"./*": "./*.js",
"./dist/*": null,

to remove a pattern from the "exports" map

A few ideas:

  • Have "exports" support folders as modules, i.e. to check for package.json and index.js. Then I can just do
"./dist/*": "./dist/*",

and dist/compiled/regenerator-runtime will be importable even if it is a directory with a package.json pointing to runtime.js

  • Or, add a config like "resolveIfNotInExports" so that e.g. dist/compiled/regenerator-runtime still resolves if I set it to null

  • Or, if we want to maintain privacy, reserve some value besides null to tell Node.js to use the default algorithm:

"./dist/*": "default",

This way we don't make anything outside dist/ public.

What alternatives have you considered?

Users just have to import Link from "next/link.js"

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.stale

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions