Skip to content

Improve logging of ERR_UNSUPPORTED_ESM_URL_SCHEME Errors #58215

@mathieumagalhaes

Description

@mathieumagalhaes

What is the problem this feature will solve?

When ERR_UNSUPPORTED_ESM_URL_SCHEME throws, we get a nice message about the wrongly used protocol.
But this does not provide enough context to pinpoint where this happens in a codebase.

What is the feature you are proposing to solve the problem?

I would like to suggest to add the URL.href or URL.pathname to the logging for ERR_UNSUPPORTED_ESM_URL_SCHEME errors.
This would mean editing this piece of code:

node/lib/internal/errors.js

Lines 1835 to 1843 in c96e96c

E('ERR_UNSUPPORTED_ESM_URL_SCHEME', (url, supported) => {
let msg = `Only URLs with a scheme in: ${formatList(supported)} are supported by the default ESM loader`;
if (isWindows && url.protocol.length === 2) {
msg +=
'. On Windows, absolute paths must be valid file:// URLs';
}
msg += `. Received protocol '${url.protocol}'`;
return msg;
}, Error);

Adding something like
msg += `. Received path '${url.pathname}`;

What alternatives have you considered?

Debugging this manually in a large codebase with external dependencies is hell.

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.

    Type

    No type

    Projects

    Status

    Awaiting Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions