Skip to content

Commit e53de96

Browse files
aduh95codebytere
authored andcommitted
esm: improve commonjs hint on module not found
Adds hint when module specifier is a file URL. PR-URL: #33220 Fixes: #33219 Reviewed-By: Guy Bedford <[email protected]>
1 parent 35aae31 commit e53de96

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

lib/internal/modules/esm/resolve.js

+3
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,9 @@ function defaultResolve(specifier, context = {}, defaultResolveUnused) {
758758
// resolved CommonJS module
759759
if (error.code === 'ERR_MODULE_NOT_FOUND' ||
760760
error.code === 'ERR_UNSUPPORTED_DIR_IMPORT') {
761+
if (StringPrototypeStartsWith(specifier, 'file://')) {
762+
specifier = fileURLToPath(specifier);
763+
}
761764
const found = resolveAsCommonJS(specifier, parentURL);
762765
if (found) {
763766
// Modify the stack and message string to include the hint

0 commit comments

Comments
 (0)