Skip to content

Commit

Permalink
module: handle empty require.resolve() options
Browse files Browse the repository at this point in the history
If require.resolve() is passed an options object, but
the paths option is not present, then use the default
require.resolve() paths.

PR-URL: #28078
Fixes: #28077
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
cjihrig authored and BridgeAR committed Jun 17, 2019
1 parent a0c5b58 commit 6014429
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/internal/modules/cjs/loader.js
Expand Up @@ -599,7 +599,9 @@ Module._resolveFilename = function(request, parent, isMain, options) {
}
}
}
} else if (options.paths !== undefined) {
} else if (options.paths === undefined) {
paths = Module._resolveLookupPaths(request, parent);
} else {
throw new ERR_INVALID_OPT_VALUE('options.paths', options.paths);
}
} else {
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/require-resolve.js
Expand Up @@ -92,3 +92,9 @@ common.expectsError(() => {
code: 'ERR_INVALID_OPT_VALUE',
type: TypeError,
});

// Verify that the default require.resolve() is used for empty options.
assert.strictEqual(
require.resolve('./printA.js', {}),
require.resolve('./printA.js')
);

0 comments on commit 6014429

Please sign in to comment.