Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -584,9 +584,6 @@ Module._resolveFilename = function(request, parent, isMain, options) {
fakeParent.paths = Module._nodeModulePaths(path);
const lookupPaths = Module._resolveLookupPaths(request, fakeParent, true);

if (!paths.includes(path))
paths.push(path);

for (var j = 0; j < lookupPaths.length; j++) {
if (!paths.includes(lookupPaths[j]))
paths.push(lookupPaths[j]);
Expand Down
13 changes: 7 additions & 6 deletions test/fixtures/require-resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ assert.throws(() => {
require.resolve('three')
}, /^Error: Cannot find module 'three'$/);

// However, it can be found if resolution contains the nested index directory.
assert.strictEqual(
require.resolve('three', { paths: [nestedIndex] }),
path.join(nestedIndex, 'three.js')
);
// If the nested-index directory is provided as a resolve path, 'three'
// cannot be found because nested-index is used as a starting point and not
// a searched directory.
assert.throws(() => {
require.resolve('three', { paths: [nestedIndex] })
}, /^Error: Cannot find module 'three'$/);

// Resolution from nested index directory also checks node_modules.
assert.strictEqual(
Expand All @@ -50,6 +51,6 @@ assert.throws(() => {
paths.unshift(nestedNodeModules);
assert.strictEqual(
require.resolve('bar', { paths }),
path.join(nestedNodeModules, 'bar.js')
path.join(nodeModules, 'bar.js')
);
}