diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js index 092e9545b43563..9fb2f1b72a5e39 100644 --- a/lib/internal/modules/cjs/loader.js +++ b/lib/internal/modules/cjs/loader.js @@ -29,6 +29,7 @@ const { ArrayPrototypeJoin, ArrayPrototypeMap, ArrayPrototypePush, + ArrayPrototypePushApply, ArrayPrototypeSlice, ArrayPrototypeSplice, ArrayPrototypeUnshift, @@ -668,12 +669,11 @@ Module._findPath = function(request, paths, isMain) { return filename; } - if (exts === undefined) { - exts = ['']; - } else { - ArrayPrototypeUnshift(exts, ''); + const extensions = ['']; + if (exts !== undefined) { + ArrayPrototypePushApply(extensions, exts); } - reportModuleNotFoundToWatchMode(basePath, exts); + reportModuleNotFoundToWatchMode(basePath, extensions); } return false; diff --git a/test/fixtures/require-resolve.js b/test/fixtures/require-resolve.js index 86bc6415c8eb55..9a7fc3385143aa 100644 --- a/test/fixtures/require-resolve.js +++ b/test/fixtures/require-resolve.js @@ -98,3 +98,8 @@ assert.strictEqual( require.resolve('./printA.js', {}), require.resolve('./printA.js') ); + +assert.strictEqual( + require.resolve('no_index/'), + path.join(__dirname, 'node_modules', 'no_index', 'lib', 'index.js'), +)