diff --git a/lib/module.js b/lib/module.js index 2d886d8a52e761..bc9d11ee0bcfce 100644 --- a/lib/module.js +++ b/lib/module.js @@ -171,8 +171,8 @@ Module._findPath = function(request, paths, isMain) { var basePath = path.resolve(curPath, request); var filename; + const rc = stat(basePath); if (!trailingSlash) { - const rc = stat(basePath); if (rc === 0) { // File. if (preserveSymlinks && !isMain) { filename = path.resolve(basePath); @@ -193,13 +193,13 @@ Module._findPath = function(request, paths, isMain) { } } - if (!filename) { + if (!filename && rc === 1) { // Directory. if (exts === undefined) exts = Object.keys(Module._extensions); filename = tryPackage(basePath, exts, isMain); } - if (!filename) { + if (!filename && rc === 1) { // Directory. // try it with each of the extensions at "index" if (exts === undefined) exts = Object.keys(Module._extensions);