From f6a00140a9e77cc06970252587b3701191fd22a0 Mon Sep 17 00:00:00 2001 From: MURAKAMI Masahiko Date: Sun, 20 Nov 2022 20:43:00 +0900 Subject: [PATCH] module: require.resolve.paths returns null with node schema require.resolve.paths should returns null with builtin module. when builtin module without `node:` schema, `paths` returns null. But, it don't return null when builtin module with `node:` schema. Fixes: https://github.com/nodejs/node/issues/45001 PR-URL: https://github.com/nodejs/node/pull/45147 Reviewed-By: Geoffrey Booth Reviewed-By: James M Snell Reviewed-By: Yagiz Nizipli --- lib/internal/modules/cjs/loader.js | 9 +++++++-- test/parallel/test-require-resolve.js | 4 ++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js index 340df162a4464f..33bc7f28a41c6c 100644 --- a/lib/internal/modules/cjs/loader.js +++ b/lib/internal/modules/cjs/loader.js @@ -751,8 +751,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);