MCPcopy Index your code
hub / github.com/nodejs/node / resolve

Function resolve

lib/internal/modules/helpers.js:200–219  ·  view source on GitHub ↗

* The `resolve` method that gets attached to module-scope `require`. * @param {string} request * @param {Parameters [3]} options * @returns {string}

(request, options)

Source from the content-addressed store, hash-verified

198 * @returns {string}
199 */
200 function resolve(request, options) {
201 validateString(request, 'request');
202 const { resolveForCJSWithHooks } = lazyCJSLoader();
203 // require.resolve() has different behaviors from the internal resolution used by
204 // Module._load:
205 // 1. When the request resolves to a non-existent built-in, it throws MODULE_NOT_FOUND
206 // instead of UNKNOWN_BUILTIN_MODULE. This is handled by resolveForCJSWithHooks.
207 // 2. If the request is a prefixed built-in, the returned value is also prefixed. This
208 // is handled below.
209 const { filename, url } = resolveForCJSWithHooks(
210 request, mod, /* isMain */ false, {
211 __proto__: null,
212 shouldSkipModuleHooks: false,
213 requireResolveOptions: options ?? {},
214 });
215 if (url === request && StringPrototypeStartsWith(request, 'node:')) {
216 return url;
217 }
218 return filename;
219 }
220
221 require.resolve = resolve;
222

Callers 4

legacyMainResolveFunction · 0.50
watch_mode.jsFile · 0.50
startFunction · 0.50

Calls 1

resolveForCJSWithHooksFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…