We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
require.resolve
1 parent 6554bd5 commit 1592741Copy full SHA for 1592741
resolvers/node/index.js
@@ -54,6 +54,19 @@ exports.resolve = function (source, file, config) {
54
return { found: true, path: null };
55
}
56
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
+
70
try {
71
const cachedFilter = function (pkg, dir) { return packageFilter(pkg, dir, config); };
72
resolvedPath = resolve(source, opts(file, config, cachedFilter));
0 commit comments