The request resolve. Assumes a normalized path is passed in (eg. repeating slashes //).
Note: In Node.js, imports resolutions are limited to requests prefixed with #. However, this package does not enforce that requirement in case you want to add custom support for non-prefixed entries.
conditions
Type: readonly string[]
An array of conditions to use when resolving the request. For reference, Node.js's default conditions are ['node', 'import'].
The order of this array does not matter; the order of condition keys in the import map is what matters instead.
Not all conditions in the array need to be met to resolve the request. It just needs enough to resolve to a path.
Errors
ERR_PACKAGE_PATH_NOT_EXPORTED
If the request is not exported by the export map
ERR_PACKAGE_IMPORT_NOT_DEFINED
If the request is not defined by the import map
ERR_INVALID_PACKAGE_CONFIG
If an object contains properties that are both paths and conditions (e.g. start with and without .)
If an object contains numeric properties
ERR_INVALID_PACKAGE_TARGET
If a resolved exports path is not a valid path (e.g. not relative or has protocol)
If a resolved path includes .. or node_modules
If a resolved path is a type that cannot be parsed
FAQ
Why do the APIs return an array of paths?
exports/imports supports passing in a fallback array to provide fallback paths if the previous one is invalid:
resolve.exports only resolves exports, whereas this package resolves both exports & imports. This comparison will only cover resolving exports.
Despite it's name, resolve.exports handles more than just exports. It takes in the entire package.json object to handle resolving . and self-references. This package only accepts exports/imports maps from package.json and is scoped to only resolving what's defined in the maps.
resolve.exports accepts the full request (e.g. foo/bar), whereas this package only accepts the requested subpath (e.g. bar).
resolve.exports only returns the first result in a fallback array. This package returns an array of results for the user to decide how to handle it.
resolve.exports supports subpath folder mapping (deprecated in Node.js v16 & removed in v17) but seems to have a bug. This package does not support subpath folder mapping because Node.js has removed it in favor of using subpath patterns.
This package also addresses many of the bugs in resolve.exports, demonstrated in this test.