Skip to content

Commit d38503a

Browse files
committed
module: prioritize current dir for local lookups
This fixes a bug where a 3rd party module found in node_modules, would be preferred over a ./local module with the same name. Fixes: #5684 PR-URL: #5689 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
1 parent ccd8188 commit d38503a

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/module.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,7 @@ Module._resolveLookupPaths = function(request, parent) {
250250
if (!parent || !parent.id || !parent.filename) {
251251
// make require('./path/to/foo') work - normally the path is taken
252252
// from realpath(__filename) but with eval there is no filename
253-
var mainPaths = ['.'].concat(modulePaths);
254-
mainPaths = Module._nodeModulePaths('.').concat(mainPaths);
253+
var mainPaths = ['.'].concat(Module._nodeModulePaths('.'), modulePaths);
255254
return [request, mainPaths];
256255
}
257256

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use strict';
2+
3+
require('../common');
4+
const assert = require('assert');
5+
const _module = require('module'); // avoid collision with global.module
6+
const lookupResults = _module._resolveLookupPaths('./lodash');
7+
const paths = lookupResults[1];
8+
9+
assert.strictEqual(paths[0], '.',
10+
'Current directory is prioritized before node_modules for local modules');

0 commit comments

Comments
 (0)