The exports field in package.json maps package import specifiers to files. It can define an entry point for the package root and expose selected subpaths; it is the modern alternative to the older main field. section 13.1.2
A mapping can use:
- "." for imports using only the package name, and a key such as "./ninjas/*" for matching subpaths. section 13.1.2
- Relative file paths as values; wildcard matches in a key map one-to-one to wildcards in its value. section 13.1.2
Listing 13.9 Defining entry points for a package
{
"name": "entry-point-example",
"private": true,
"type": "module", #A
"exports": { #B
".": "./lib/index.js", #B
"./ninjas/*": "./lib/ninjas/*.js" #B
} #B
}This configuration maps the package root to its index file and ninja subpaths to matching files. section 13.1.2
After Node.js finds a package, it checks its package.json for an exports mapping. When debugging resolution, inspect the manifest in the local node_modules package: it may differ from the package’s source manifest. section 3.2.2 section 13.1.2
