Skip to content

Commit

Permalink
module: prioritize current dir for local lookups
Browse files Browse the repository at this point in the history
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 <benjamingr@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
  • Loading branch information
phillipj committed Mar 29, 2016
1 parent ccd8188 commit d38503a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,7 @@ Module._resolveLookupPaths = function(request, parent) {
if (!parent || !parent.id || !parent.filename) {
// make require('./path/to/foo') work - normally the path is taken
// from realpath(__filename) but with eval there is no filename
var mainPaths = ['.'].concat(modulePaths);
mainPaths = Module._nodeModulePaths('.').concat(mainPaths);
var mainPaths = ['.'].concat(Module._nodeModulePaths('.'), modulePaths);
return [request, mainPaths];
}

Expand Down
10 changes: 10 additions & 0 deletions test/parallel/test-module-relative-lookup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';

require('../common');
const assert = require('assert');
const _module = require('module'); // avoid collision with global.module
const lookupResults = _module._resolveLookupPaths('./lodash');
const paths = lookupResults[1];

assert.strictEqual(paths[0], '.',
'Current directory is prioritized before node_modules for local modules');

0 comments on commit d38503a

Please sign in to comment.