diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js index 614ee758d2b5de..93681ea243b08c 100644 --- a/lib/internal/modules/cjs/loader.js +++ b/lib/internal/modules/cjs/loader.js @@ -737,8 +737,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) + )) { debug('looking for %j in []', request); return null; } diff --git a/test/parallel/test-require-resolve.js b/test/parallel/test-require-resolve.js index ab58033e2c9b5c..a38a8e074ab85d 100644 --- a/test/parallel/test-require-resolve.js +++ b/test/parallel/test-require-resolve.js @@ -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);