* 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)
| 1038 | * @param {string} parentURL - The URL of the parent module. |
| 1039 | */ |
| 1040 | function 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 | |
| 1054 | module.exports = { |
| 1055 | decorateErrorWithCommonJSHints, |
no test coverage detected
searching dependent graphs…