Skip to content

Commit 58fc168

Browse files
committed
module: handle empty require.resolve() options
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]>
1 parent 0cd112a commit 58fc168

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/internal/modules/cjs/loader.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,9 @@ Module._resolveFilename = function(request, parent, isMain, options) {
598598
}
599599
}
600600
}
601-
} else if (options.paths !== undefined) {
601+
} else if (options.paths === undefined) {
602+
paths = Module._resolveLookupPaths(request, parent);
603+
} else {
602604
throw new ERR_INVALID_OPT_VALUE('options.paths', options.paths);
603605
}
604606
} else {

test/fixtures/require-resolve.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,9 @@ common.expectsError(() => {
9292
code: 'ERR_INVALID_OPT_VALUE',
9393
type: TypeError,
9494
});
95+
96+
// Verify that the default require.resolve() is used for empty options.
97+
assert.strictEqual(
98+
require.resolve('./printA.js', {}),
99+
require.resolve('./printA.js')
100+
);

0 commit comments

Comments
 (0)