Gathering detailed insights and metrics for resolve
Gathering detailed insights and metrics for resolve
Gathering detailed insights and metrics for resolve
Gathering detailed insights and metrics for resolve
resolve-from
Resolve the path of a module like `require.resolve()` but from a given path
@jridgewell/resolve-uri
Resolve a URI relative to an optional base URI
resolve-url
Like Node.js’ `path.resolve`/`url.resolve` for the browser.
resolve-cwd
Resolve the path of a module like `require.resolve()` but from the current working directory
Implements the node.js require.resolve() algorithm
npm install resolve
Typescript
Module System
Min. Node Version
Node Version
NPM Version
96.6
Supply Chain
99.6
Quality
77.8
Maintenance
100
Vulnerability
99.6
License
JavaScript (100%)
Total Downloads
17,949,471,437
Last Day
6,271,778
Last Week
99,267,253
Last Month
427,796,026
Last Year
4,272,664,502
MIT License
784 Stars
679 Commits
186 Forks
15 Watchers
4 Branches
77 Contributors
Updated on Jun 26, 2025
Minified
Minified + Gzipped
Latest Version
1.22.10
Package Id
resolve@1.22.10
Unpacked Size
142.21 kB
Size
26.90 kB
File Count
97
NPM Version
10.9.2
Node Version
23.4.0
Published on
Dec 19, 2024
Cumulative downloads
Total Downloads
Last Day
-7.5%
6,271,778
Compared to previous day
Last Week
-7.3%
99,267,253
Compared to previous week
Last Month
1%
427,796,026
Compared to previous month
Last Year
14.8%
4,272,664,502
Compared to previous year
implements the node require.resolve()
algorithm such that you can require.resolve()
on behalf of a file asynchronously and synchronously
asynchronously resolve:
1var resolve = require('resolve/async'); // or, require('resolve') 2resolve('tap', { basedir: __dirname }, function (err, res) { 3 if (err) console.error(err); 4 else console.log(res); 5});
$ node example/async.js
/home/substack/projects/node-resolve/node_modules/tap/lib/main.js
synchronously resolve:
1var resolve = require('resolve/sync'); // or, `require('resolve').sync 2var res = resolve('tap', { basedir: __dirname }); 3console.log(res);
$ node example/sync.js
/home/substack/projects/node-resolve/node_modules/tap/lib/main.js
1var resolve = require('resolve'); 2var async = require('resolve/async'); 3var sync = require('resolve/sync');
For both the synchronous and asynchronous methods, errors may have any of the following err.code
values:
MODULE_NOT_FOUND
: the given path string (id
) could not be resolved to a moduleINVALID_BASEDIR
: the specified opts.basedir
doesn't exist, or is not a directoryINVALID_PACKAGE_MAIN
: a package.json
was encountered with an invalid main
property (eg. not a string)Asynchronously resolve the module path string id
into cb(err, res [, pkg])
, where pkg
(if defined) is the data from package.json
.
options are:
opts.basedir - directory to begin resolving from
opts.package - package.json
data applicable to the module being loaded
opts.extensions - array of file extensions to search in order
opts.includeCoreModules - set to false
to exclude node core modules (e.g. fs
) from the search
opts.readFile - how to read files asynchronously
opts.isFile - function to asynchronously test whether a file exists
opts.isDirectory - function to asynchronously test whether a file exists and is a directory
opts.realpath - function to asynchronously resolve a potential symlink to its real path
opts.readPackage(readFile, pkgfile, cb)
- function to asynchronously read and parse a package.json file
opts.readFile
or fs.readFile
if not specifiedopts.packageFilter(pkg, pkgfile, dir)
- transform the parsed package.json contents before looking at the "main" field
opts.pathFilter(pkg, path, relativePath)
- transform a path within a package
opts.paths - require.paths array to use if nothing is found on the normal node_modules
recursive walk (probably don't use this)
For advanced users, paths
can also be a opts.paths(request, start, opts)
function
node_modules
resolutionopts.packageIterator(request, start, opts)
- return the list of candidate paths where the packages sources may be found (probably don't use this)
node_modules
resolutionopts.moduleDirectory - directory (or directories) in which to recursively look for modules. default: "node_modules"
opts.preserveSymlinks - if true, doesn't resolve basedir
to real path before resolving.
This is the way Node resolves dependencies when executed with the --preserve-symlinks flag.
Note: this property is currently true
by default but it will be changed to
false
in the next major version because Node's resolution algorithm does not preserve symlinks by default.
default opts
values:
1{ 2 paths: [], 3 basedir: __dirname, 4 extensions: ['.js'], 5 includeCoreModules: true, 6 readFile: fs.readFile, 7 isFile: function isFile(file, cb) { 8 fs.stat(file, function (err, stat) { 9 if (!err) { 10 return cb(null, stat.isFile() || stat.isFIFO()); 11 } 12 if (err.code === 'ENOENT' || err.code === 'ENOTDIR') return cb(null, false); 13 return cb(err); 14 }); 15 }, 16 isDirectory: function isDirectory(dir, cb) { 17 fs.stat(dir, function (err, stat) { 18 if (!err) { 19 return cb(null, stat.isDirectory()); 20 } 21 if (err.code === 'ENOENT' || err.code === 'ENOTDIR') return cb(null, false); 22 return cb(err); 23 }); 24 }, 25 realpath: function realpath(file, cb) { 26 var realpath = typeof fs.realpath.native === 'function' ? fs.realpath.native : fs.realpath; 27 realpath(file, function (realPathErr, realPath) { 28 if (realPathErr && realPathErr.code !== 'ENOENT') cb(realPathErr); 29 else cb(null, realPathErr ? file : realPath); 30 }); 31 }, 32 readPackage: function defaultReadPackage(readFile, pkgfile, cb) { 33 readFile(pkgfile, function (readFileErr, body) { 34 if (readFileErr) cb(readFileErr); 35 else { 36 try { 37 var pkg = JSON.parse(body); 38 cb(null, pkg); 39 } catch (jsonErr) { 40 cb(null); 41 } 42 } 43 }); 44 }, 45 moduleDirectory: 'node_modules', 46 preserveSymlinks: true 47}
Synchronously resolve the module path string id
, returning the result and
throwing an error when id
can't be resolved.
options are:
opts.basedir - directory to begin resolving from
opts.extensions - array of file extensions to search in order
opts.includeCoreModules - set to false
to exclude node core modules (e.g. fs
) from the search
opts.readFileSync - how to read files synchronously
opts.isFile - function to synchronously test whether a file exists
opts.isDirectory - function to synchronously test whether a file exists and is a directory
opts.realpathSync - function to synchronously resolve a potential symlink to its real path
opts.readPackageSync(readFileSync, pkgfile)
- function to synchronously read and parse a package.json file
opts.readFileSync
or fs.readFileSync
if not specifiedopts.packageFilter(pkg, dir)
- transform the parsed package.json contents before looking at the "main" field
opts.pathFilter(pkg, path, relativePath)
- transform a path within a package
opts.paths - require.paths array to use if nothing is found on the normal node_modules
recursive walk (probably don't use this)
For advanced users, paths
can also be a opts.paths(request, start, opts)
function
node_modules
resolutionopts.packageIterator(request, start, opts)
- return the list of candidate paths where the packages sources may be found (probably don't use this)
node_modules
resolutionopts.moduleDirectory - directory (or directories) in which to recursively look for modules. default: "node_modules"
opts.preserveSymlinks - if true, doesn't resolve basedir
to real path before resolving.
This is the way Node resolves dependencies when executed with the --preserve-symlinks flag.
Note: this property is currently true
by default but it will be changed to
false
in the next major version because Node's resolution algorithm does not preserve symlinks by default.
default opts
values:
1{ 2 paths: [], 3 basedir: __dirname, 4 extensions: ['.js'], 5 includeCoreModules: true, 6 readFileSync: fs.readFileSync, 7 isFile: function isFile(file) { 8 try { 9 var stat = fs.statSync(file); 10 } catch (e) { 11 if (e && (e.code === 'ENOENT' || e.code === 'ENOTDIR')) return false; 12 throw e; 13 } 14 return stat.isFile() || stat.isFIFO(); 15 }, 16 isDirectory: function isDirectory(dir) { 17 try { 18 var stat = fs.statSync(dir); 19 } catch (e) { 20 if (e && (e.code === 'ENOENT' || e.code === 'ENOTDIR')) return false; 21 throw e; 22 } 23 return stat.isDirectory(); 24 }, 25 realpathSync: function realpathSync(file) { 26 try { 27 var realpath = typeof fs.realpathSync.native === 'function' ? fs.realpathSync.native : fs.realpathSync; 28 return realpath(file); 29 } catch (realPathErr) { 30 if (realPathErr.code !== 'ENOENT') { 31 throw realPathErr; 32 } 33 } 34 return file; 35 }, 36 readPackageSync: function defaultReadPackageSync(readFileSync, pkgfile) { 37 var body = readFileSync(pkgfile); 38 try { 39 var pkg = JSON.parse(body); 40 return pkg; 41 } catch (jsonErr) {} 42 }, 43 moduleDirectory: 'node_modules', 44 preserveSymlinks: true 45}
With npm do:
1npm install resolve
MIT
No vulnerabilities found.
Reason
security policy file detected
Details
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
3 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 2
Reason
badge detected: InProgress
Reason
Found 1/30 approved changesets -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-06-30
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