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 <[email protected]>
Reviewed-By: Yongsheng Zhang <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Anto Aravinth <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • 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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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.