diff --git a/lib/module.js b/lib/module.js index 844b683940c2a4..598b17abb2abc1 100644 --- a/lib/module.js +++ b/lib/module.js @@ -129,7 +129,7 @@ const noopDeprecateRequireDot = util.deprecate(function() {}, Module._findPath = function(request, paths) { var exts = Object.keys(Module._extensions); - if (request.charAt(0) === '/') { + if (path.isAbsolute(request)) { paths = ['']; } @@ -142,6 +142,8 @@ Module._findPath = function(request, paths) { // For each path for (var i = 0, PL = paths.length; i < PL; i++) { + // Don't search further if path doesn't exist + if (paths[i] && internalModuleStat(paths[i]) < 1) continue; var basePath = path.resolve(paths[i], request); var filename;