Skip to content

Commit

Permalink
esm: improve commonjs hint on module not found
Browse files Browse the repository at this point in the history
Adds hint when module specifier is a file URL.

PR-URL: #33220
Fixes: #33219
Reviewed-By: Guy Bedford <[email protected]>
  • Loading branch information
aduh95 authored and codebytere committed Jun 7, 2020
1 parent 9cc7b24 commit 1c238b6
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/internal/modules/esm/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,9 @@ function defaultResolve(specifier, context = {}, defaultResolveUnused) {
// resolved CommonJS module
if (error.code === 'ERR_MODULE_NOT_FOUND' ||
error.code === 'ERR_UNSUPPORTED_DIR_IMPORT') {
if (StringPrototypeStartsWith(specifier, 'file://')) {
specifier = fileURLToPath(specifier);
}
const found = resolveAsCommonJS(specifier, parentURL);
if (found) {
// Modify the stack and message string to include the hint
Expand Down

0 comments on commit 1c238b6

Please sign in to comment.