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.

Refs: nodejs#31906
  • Loading branch information
aduh95 committed May 14, 2020
1 parent 112c552 commit ed3dfc5
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 ed3dfc5

Please sign in to comment.