diff --git a/lib/module.js b/lib/module.js index 29a23776d79..f633d62c490 100644 --- a/lib/module.js +++ b/lib/module.js @@ -170,6 +170,8 @@ Module._findPath = function(request, paths) { } if (!filename) { + if (exts === undefined) + exts = Object.keys(Module._extensions); filename = tryPackage(basePath, exts); } diff --git a/test/fixtures/module-require/not-found/node_modules/module1/package.json b/test/fixtures/module-require/not-found/node_modules/module1/package.json new file mode 100644 index 00000000000..b5018d73b21 --- /dev/null +++ b/test/fixtures/module-require/not-found/node_modules/module1/package.json @@ -0,0 +1,3 @@ +{ + "main": "doesnotexist" +} diff --git a/test/fixtures/module-require/not-found/trailingSlash.js b/test/fixtures/module-require/not-found/trailingSlash.js new file mode 100644 index 00000000000..4ac6cba9ca8 --- /dev/null +++ b/test/fixtures/module-require/not-found/trailingSlash.js @@ -0,0 +1 @@ +require('module1/'); diff --git a/test/parallel/test-require-exceptions.js b/test/parallel/test-require-exceptions.js index e7a191b47ad..0e61ad2f3fd 100644 --- a/test/parallel/test-require-exceptions.js +++ b/test/parallel/test-require-exceptions.js @@ -14,9 +14,21 @@ assert.throws(function() { // Requiring a module that does not exist should throw an // error with its `code` set to MODULE_NOT_FOUND -assert.throws(function() { - require(common.fixturesDir + '/DOES_NOT_EXIST'); -}, function(e) { - assert.equal('MODULE_NOT_FOUND', e.code); - return true; -}); +assertModuleNotFound('/DOES_NOT_EXIST'); + +assertExists('/module-require/not-found/trailingSlash.js'); +assertExists('/module-require/not-found/node_modules/module1/package.json'); +assertModuleNotFound('/module-require/not-found/trailingSlash'); + +function assertModuleNotFound(path) { + assert.throws(function() { + require(common.fixturesDir + path); + }, function(e) { + assert.strictEqual(e.code, 'MODULE_NOT_FOUND'); + return true; + }); +} + +function assertExists(fixture) { + assert(common.fileExists(common.fixturesDir + fixture)); +}