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 <guybedford@gmail.com>
  • Loading branch information
aduh95 authored and codebytere committed Jun 9, 2020
1 parent 4f6e4ae commit a029dca
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/internal/modules/esm/resolve.js
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 a029dca

Please sign in to comment.