Skip to content

[Native ES Modules] Support for exports subpath aliasing #9565

Closed
@aldeed

Description

@aldeed

@SimenB Great to see the list in #9430 and progress being made on it. Lots of complicated issues.

I don't see an explicit mention of handling exports object from a package when resolving package identifiers.

For example, given this in package.json:

"exports": {
    "./": "./lib/"
  },

Assuming the ESM package has a file located at /lib/foo.js, you would instead import from "package-name/foo.js" and then Node transforms that to add /lib layer.

Currently latest Jest (using Babel for parsing) does not respect this exports mapping so we have to add a matching Jest config for every dependency package that uses it:

moduleNameMapper: {
  "^package-name/(.*)$": "package-name/lib/$1"
},

Will this "just work" when native ESM support lands? If so, great, you can close this.

If not I think it should be added to your list. Thanks!

Ref: https://nodejs.org/dist/latest-v12.x/docs/api/esm.html#esm_package_exports

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions