Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

esm: better error message for unsupported URL #31129

Closed
wants to merge 1 commit into from
Closed

esm: better error message for unsupported URL #31129

wants to merge 1 commit into from

Conversation

Hakerh400
Copy link
Contributor

@Hakerh400 Hakerh400 commented Dec 29, 2019

The default ESM loader supports only file and data URLs.
This PR adds better error message for it.

Fixes #31120

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • documentation is changed or added
  • commit message follows commit guidelines

@nodejs-github-bot nodejs-github-bot added errors Issues and PRs related to JavaScript errors originated in Node.js core. esm Issues and PRs related to the ECMAScript Modules implementation. labels Dec 29, 2019
@Hakerh400
Copy link
Contributor Author

Hakerh400 commented Dec 29, 2019

test/es-module/test-esm-dynamic-import.js

// TODO(jkrems): Right now this doesn't hit a protocol error because the
// module resolution step already rejects it. These arguably should be
// protocol errors.
expectMissingModuleError(import('node:fs'));
expectMissingModuleError(import('http://example.com/foo.js'));

This is the only test failing right now. The problem is that the loader converts the url to a file url and ignores the url scheme, producing a misleading error message (and it may probably load a wrong module). Should we update this test to check for ERR_UNSUPPORTED_ESM_URL_SCHEME, or should we delete this new error type and stick with the generic ERR_MODULE_NOT_FOUND?

Copy link
Member

@devsnek devsnek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use parsed.scheme a few lines down.

doc/api/errors.md Outdated Show resolved Hide resolved
Copy link
Contributor

@guybedford guybedford left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, the approach looks great.

The test failures can be fixed by just changing the test expectations in https://github.com/nodejs/node/blob/master/test/es-module/test-esm-dynamic-import.js#L60. Note that the errors exactly align with a TODO comment @jkrems included previously.

The default ESM loader supports only file and data URLs.
This PR adds better error message for it.
@nodejs-github-bot
Copy link
Collaborator

@Trott
Copy link
Member

Trott commented Dec 31, 2019

This is stalled on two issues in CI (nodejs/build#2116 and nodejs/build#2115) that will hopefully be resolved soon.

@BridgeAR BridgeAR added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Jan 2, 2020
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@BridgeAR
Copy link
Member

BridgeAR commented Jan 3, 2020

Landed in a25a628 🎉

@BridgeAR BridgeAR closed this Jan 3, 2020
BridgeAR pushed a commit to BridgeAR/node that referenced this pull request Jan 3, 2020
The default ESM loader supports only file and data URLs.
This PR adds better error message for it.

PR-URL: nodejs#31129
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: Guy Bedford <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
@Hakerh400 Hakerh400 deleted the esm-url branch January 3, 2020 14:50
BridgeAR pushed a commit that referenced this pull request Jan 3, 2020
The default ESM loader supports only file and data URLs.
This PR adds better error message for it.

PR-URL: #31129
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: Guy Bedford <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
@BridgeAR BridgeAR mentioned this pull request Jan 7, 2020
MylesBorins pushed a commit that referenced this pull request Jan 12, 2020
The default ESM loader supports only file and data URLs.
This PR adds better error message for it.

PR-URL: #31129
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: Guy Bedford <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
BethGriggs pushed a commit that referenced this pull request Feb 6, 2020
The default ESM loader supports only file and data URLs.
This PR adds better error message for it.

PR-URL: #31129
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: Guy Bedford <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
@MylesBorins MylesBorins mentioned this pull request Feb 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. errors Issues and PRs related to JavaScript errors originated in Node.js core. esm Issues and PRs related to the ECMAScript Modules implementation.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

import does not work correctly
8 participants