Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1592741

Browse filesBrowse files
committed
[Fix/New] Node resolver: Try to use require.resolve when suitable
1 parent 6554bd5 commit 1592741
Copy full SHA for 1592741

File tree

1 file changed

+13
-0
lines changed
Filter options

1 file changed

+13
-0
lines changed

‎resolvers/node/index.js

Copy file name to clipboardExpand all lines: resolvers/node/index.js
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,19 @@ exports.resolve = function (source, file, config) {
5454
return { found: true, path: null };
5555
}
5656

57+
// If this looks like a bare package name (not relative, not qualified
58+
// with an extension) and we're on a fresh enough version of Node.js
59+
// to have `require.resolve`, attempt that first.
60+
if (require.resolve && source.indexOf('.') === -1) {
61+
try {
62+
resolvedPath = require.resolve(source);
63+
log('Resolved to:', resolvedPath);
64+
return { found: true, path: resolvedPath };
65+
} catch (err) {
66+
log('require.resolve threw error:', err);
67+
}
68+
}
69+
5770
try {
5871
const cachedFilter = function (pkg, dir) { return packageFilter(pkg, dir, config); };
5972
resolvedPath = resolve(source, opts(file, config, cachedFilter));

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.