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

Function decorateErrorWithCommonJSHints

lib/internal/modules/esm/resolve.js:1040–1052  ·  view source on GitHub ↗

* Decorates the given error with a hint for CommonJS modules. * @param {Error} error - The error to decorate. * @param {string} specifier - The specifier that was attempted to be imported. * @param {string} parentURL - The URL of the parent module.

(error, specifier, parentURL)

Source from the content-addressed store, hash-verified

1038 * @param {string} parentURL - The URL of the parent module.
1039 */
1040function decorateErrorWithCommonJSHints(error, specifier, parentURL) {
1041 const found = resolveAsCommonJS(specifier, parentURL);
1042 if (found && found !== specifier) { // Don't suggest the same input the user provided.
1043 // Modify the stack and message string to include the hint
1044 const endOfFirstLine = StringPrototypeIndexOf(error.stack, '\n');
1045 const hint = `Did you mean to import ${JSONStringify(found)}?`;
1046 error.stack =
1047 StringPrototypeSlice(error.stack, 0, endOfFirstLine) + '\n' +
1048 hint +
1049 StringPrototypeSlice(error.stack, endOfFirstLine);
1050 error.message += `\n${hint}`;
1051 }
1052}
1053
1054module.exports = {
1055 decorateErrorWithCommonJSHints,

Callers 1

defaultResolveFunction · 0.85

Calls 1

resolveAsCommonJSFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…