Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

module: require.resolve.paths returns null with node schema #45147

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/internal/modules/cjs/loader.js
Expand Up @@ -712,8 +712,13 @@ if (isWindows) {
}

Module._resolveLookupPaths = function(request, parent) {
if (BuiltinModule.canBeRequiredByUsers(request) &&
BuiltinModule.canBeRequiredWithoutScheme(request)) {
if ((
StringPrototypeStartsWith(request, 'node:') &&
BuiltinModule.canBeRequiredByUsers(StringPrototypeSlice(request, 5))
) || (
BuiltinModule.canBeRequiredByUsers(request) &&
BuiltinModule.canBeRequiredWithoutScheme(request)
)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is in the CommonJS loader; what about the ESM loader? Does it use this same logic?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This same logic is not used in ESM Loader.

debug('looking for %j in []', request);
return null;
}
Expand Down
4 changes: 4 additions & 0 deletions test/parallel/test-require-resolve.js
Expand Up @@ -63,6 +63,10 @@ require(fixtures.path('resolve-paths', 'default', 'verify-paths.js'));
assert.strictEqual(require.resolve.paths(mod), null);
});

builtinModules.forEach((mod) => {
assert.strictEqual(require.resolve.paths(`node:${mod}`), null);
});

// node_modules.
const resolvedPaths = require.resolve.paths('eslint');
assert.strictEqual(Array.isArray(resolvedPaths), true);
Expand Down