diff --git a/lib/module.js b/lib/module.js index 74db325dabe276..b992ca8faf3add 100644 --- a/lib/module.js +++ b/lib/module.js @@ -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]; } diff --git a/test/parallel/test-module-relative-lookup.js b/test/parallel/test-module-relative-lookup.js new file mode 100644 index 00000000000000..002ae1a8fb7776 --- /dev/null +++ b/test/parallel/test-module-relative-lookup.js @@ -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');