Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6014429

Browse filesBrowse 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
Copy full SHA for 6014429

File tree

Expand file treeCollapse file tree

2 files changed

+9
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+9
-1
lines changed
Open diff view settings
Collapse file

‎lib/internal/modules/cjs/loader.js‎

Copy file name to clipboardExpand all lines: lib/internal/modules/cjs/loader.js
+3-1Lines 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 {
Collapse file

‎test/fixtures/require-resolve.js‎

Copy file name to clipboardExpand all lines: test/fixtures/require-resolve.js
+6Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.