Gathering detailed insights and metrics for enhanced-resolve
Gathering detailed insights and metrics for enhanced-resolve
Gathering detailed insights and metrics for enhanced-resolve
Gathering detailed insights and metrics for enhanced-resolve
@types/enhanced-resolve
Stub TypeScript definitions entry for enhanced-resolve, which provides its own types definitions
postcss-import-resolver
Customize postcss-import resolve with enhanced-resolve
enhanced-resolve-jest
Resolver for Jest which uses the enhanced-resolve module
@chialab/node-resolve
A promise based node resolution library based on enhanced-resolve.
Offers an async require.resolve function. It's highly configurable.
npm install enhanced-resolve
Typescript
Module System
Min. Node Version
Node Version
NPM Version
99
Supply Chain
100
Quality
88
Maintenance
100
Vulnerability
100
License
JavaScript (99.98%)
Shell (0.02%)
Total Downloads
7,574,156,910
Last Day
1,991,743
Last Week
38,313,009
Last Month
169,146,820
Last Year
1,799,183,457
MIT License
965 Stars
884 Commits
195 Forks
19 Watchers
8 Branches
136 Contributors
Updated on Jun 28, 2025
Minified
Minified + Gzipped
Latest Version
5.18.2
Package Id
enhanced-resolve@5.18.2
Unpacked Size
217.52 kB
Size
41.65 kB
File Count
48
NPM Version
10.9.2
Node Version
22.13.1
Published on
Jun 24, 2025
Cumulative downloads
Total Downloads
Last Day
-7.7%
1,991,743
Compared to previous day
Last Week
-8.5%
38,313,009
Compared to previous week
Last Month
0.2%
169,146,820
Compared to previous month
Last Year
16.4%
1,799,183,457
Compared to previous year
2
25
Offers an async require.resolve function. It's highly configurable.
1# npm 2npm install enhanced-resolve 3# or Yarn 4yarn add enhanced-resolve
There is a Node.js API which allows to resolve requests according to the Node.js resolving rules.
Sync and async APIs are offered. A create
method allows to create a custom resolve function.
1const resolve = require("enhanced-resolve"); 2 3resolve("/some/path/to/folder", "module/dir", (err, result) => { 4 result; // === "/some/path/node_modules/module/dir/index.js" 5}); 6 7resolve.sync("/some/path/to/folder", "../../dir"); 8// === "/some/path/dir/index.js" 9 10const myResolve = resolve.create({ 11 // or resolve.create.sync 12 extensions: [".ts", ".js"], 13 // see more options below 14}); 15 16myResolve("/some/path/to/folder", "ts-module", (err, result) => { 17 result; // === "/some/node_modules/ts-module/index.ts" 18});
The easiest way to create a resolver is to use the createResolver
function on ResolveFactory
, along with one of the supplied File System implementations.
1const fs = require("fs");
2const { CachedInputFileSystem, ResolverFactory } = require("enhanced-resolve");
3
4// create a resolver
5const myResolver = ResolverFactory.createResolver({
6 // Typical usage will consume the `fs` + `CachedInputFileSystem`, which wraps Node.js `fs` to add caching.
7 fileSystem: new CachedInputFileSystem(fs, 4000),
8 extensions: [".js", ".json"],
9 /* any other resolver options here. Options/defaults can be seen below */
10});
11
12// resolve a file with the new resolver
13const context = {};
14const lookupStartPath = "/Users/webpack/some/root/dir";
15const request = "./path/to-look-up.js";
16const resolveContext = {};
17myResolver.resolve(
18 context,
19 lookupStartPath,
20 request,
21 resolveContext,
22 (err /* Error */, filepath /* string */) => {
23 // Do something with the path
24 },
25);
Field | Default | Description |
---|---|---|
alias | [] | A list of module alias configurations or an object which maps key to value |
aliasFields | [] | A list of alias fields in description files |
extensionAlias | {} | An object which maps extension to extension aliases |
cachePredicate | function() { return true }; | A function which decides whether a request should be cached or not. An object is passed to the function with path and request properties. |
cacheWithContext | true | If unsafe cache is enabled, includes request.context in the cache key |
conditionNames | [] | A list of exports field condition names |
descriptionFiles | ["package.json"] | A list of description files to read from |
enforceExtension | false | Enforce that a extension from extensions must be used |
exportsFields | ["exports"] | A list of exports fields in description files |
extensions | [".js", ".json", ".node"] | A list of extensions which should be tried for files |
fallback | [] | Same as alias , but only used if default resolving fails |
fileSystem | The file system which should be used | |
fullySpecified | false | Request passed to resolve is already fully specified and extensions or main files are not resolved for it (they are still resolved for internal requests) |
mainFields | ["main"] | A list of main fields in description files |
mainFiles | ["index"] | A list of main files in directories |
modules | ["node_modules"] | A list of directories to resolve modules from, can be absolute path or folder name |
plugins | [] | A list of additional resolve plugins which should be applied |
resolver | undefined | A prepared Resolver to which the plugins are attached |
resolveToContext | false | Resolve to a context instead of a file |
preferRelative | false | Prefer to resolve module requests as relative request and fallback to resolving as module |
preferAbsolute | false | Prefer to resolve server-relative urls as absolute paths before falling back to resolve in roots |
restrictions | [] | A list of resolve restrictions |
roots | [] | A list of root paths |
symlinks | true | Whether to resolve symlinks to their symlinked location |
unsafeCache | false | Use this cache object to unsafely cache the successful requests |
Similar to webpack
, the core of enhanced-resolve
functionality is implemented as individual plugins that are executed using tapable
.
These plugins can extend the functionality of the library, adding other ways for files/contexts to be resolved.
A plugin should be a class
(or its ES5 equivalent) with an apply
method. The apply
method will receive a resolver
instance, that can be used to hook in to the event system.
1class MyResolverPlugin {
2 constructor(source, target) {
3 this.source = source;
4 this.target = target;
5 }
6
7 apply(resolver) {
8 const target = resolver.ensureHook(this.target);
9 resolver
10 .getHook(this.source)
11 .tapAsync("MyResolverPlugin", (request, resolveContext, callback) => {
12 // Any logic you need to create a new `request` can go here
13 resolver.doResolve(target, request, null, resolveContext, callback);
14 });
15 }
16}
Plugins are executed in a pipeline, and register which event they should be executed before/after. In the example above, source
is the name of the event that starts the pipeline, and target
is what event this plugin should fire, which is what continues the execution of the pipeline. For an example of how these different plugin events create a chain, see lib/ResolverFactory.js
, in the //// pipeline ////
section.
It's allowed to escape #
as \0#
to avoid parsing it as fragment.
enhanced-resolve will try to resolve requests containing #
as path and as fragment, so it will automatically figure out if ./some#thing
means .../some.js#thing
or .../some#thing.js
. When a #
is resolved as path it will be escaped in the result. Here: .../some\0#thing.js
.
1yarn test
If you are using webpack
, and you want to pass custom options to enhanced-resolve
, the options are passed from the resolve
key of your webpack configuration e.g.:
resolve: {
extensions: ['.js', '.jsx'],
modules: [path.resolve(__dirname, 'src'), 'node_modules'],
plugins: [new DirectoryNamedWebpackPlugin()]
...
},
Copyright (c) 2012-2019 JS Foundation and other contributors
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
11 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 10
Reason
GitHub workflow tokens follow principle of least privilege
Details
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
Found 4/14 approved changesets -- score normalized to 2
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-06-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More