Skip to content

Commit 6014429

Browse files
cjihrigBridgeAR
authored andcommitted
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 <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>
1 parent a0c5b58 commit 6014429

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
@@ -599,7 +599,9 @@ Module._resolveFilename = function(request, parent, isMain, options) {
599599
}
600600
}
601601
}
602-
} else if (options.paths !== undefined) {
602+
} else if (options.paths === undefined) {
603+
paths = Module._resolveLookupPaths(request, parent);
604+
} else {
603605
throw new ERR_INVALID_OPT_VALUE('options.paths', options.paths);
604606
}
605607
} 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)