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: fix imports from non-file module #42881

Merged
merged 3 commits into from
Apr 29, 2022

Conversation

aduh95
Copy link
Contributor

@aduh95 aduh95 commented Apr 27, 2022

Calling fileURLToPath on a possibly non-file URL throws. Converting to a path is not necessary anyway, as it's already common to see a URL in error messages rather than a path.

Fixes: #42860

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/modules

@nodejs-github-bot nodejs-github-bot added esm Issues and PRs related to the ECMAScript Modules implementation. needs-ci PRs that need a full CI run. labels Apr 27, 2022
Comment on lines -1018 to -1019
const parentURL = fileURLToPath(parsedParentURL?.href);

Copy link
Member

Choose a reason for hiding this comment

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

There was a reason for this (I'm pretty sure not doing this will break something), but I can't remember what it was. @bmeck do you remember?

Copy link
Member

@JakobJingleheimer JakobJingleheimer Apr 27, 2022

Choose a reason for hiding this comment

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

OH! I partially remember! It's when something is wrong with parsedParentURL—that's why it uses ?.. Without this, the error message was too confusing, like " is not allowed" (where there should be something at the front). Adding it provided an important clue to what is wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We're checking that parsedParentURL is truthy the line just before that, I don't think the ?. could ever take effect. Arguably it's fixing a bigger issue than a confusing error message, I'd be inclined to land this anyway. We can always improve things later if the original problem comes back. wdyt?

Copy link
Member

@GeoffreyBooth GeoffreyBooth left a comment

Choose a reason for hiding this comment

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

I’m assuming you’ve checked that this is okay with ERR_NETWORK_IMPORT_DISALLOWED.

To answer @JakobJingleheimer’s question, I’d guess we were trying to create a more readable error message, telling the user which file had the issue? And assuming that it would be more expected to tell the user their file as a path rather than as a URL.

@JakobJingleheimer
Copy link
Member

JakobJingleheimer commented Apr 27, 2022

Maaaybe, but I think it was more than metely pretty-fying. At the least, I think it made the path intelligible in some circumstance it otherwise wasn't. I specifically remember talking to Bradley about this line, but slack ate it (it's beyond the retention age for free Slack 😰).

Maybe it had to do with normalising the same error message across CJS and ESM and there was an issue filed this fixed? 🕵️‍♂️ nvmd, I was thinking of #39787 which was resolved via a documentation update.

I guess it can't be that important or I would have put a code comment.

@JakobJingleheimer
Copy link
Member

@aduh95 please see my inline comment. I lost quite a bit of time when I was testing a specific scenario for #36328 because of the missing information in the error message that fileURLToPath() reveals. If needed, I can try to re-discover what the specific repro steps were for this (so it can be addressed in a different way).

@aduh95
Copy link
Contributor Author

aduh95 commented Apr 27, 2022

I can try to re-discover what the specific repro steps were for this (so it can be addressed in a different way).

Having a test for that would be ideal 👍 It can also be taken to its own PR as I'd like this patch to land ASAP.

Copy link
Member

@JakobJingleheimer JakobJingleheimer left a comment

Choose a reason for hiding this comment

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

Sure! That works for me!

@aduh95 aduh95 added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. labels Apr 27, 2022
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Apr 27, 2022
@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot
Copy link
Collaborator

@aduh95 aduh95 added the commit-queue Add this label to land a pull request using GitHub Actions. label Apr 29, 2022
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Apr 29, 2022
@nodejs-github-bot nodejs-github-bot merged commit 27ecf1d into nodejs:master Apr 29, 2022
@nodejs-github-bot
Copy link
Collaborator

Landed in 27ecf1d

@aduh95 aduh95 deleted the fix-import-from-data-modules branch April 29, 2022 14:31
targos pushed a commit that referenced this pull request May 2, 2022
Fixes: #42860

PR-URL: #42881
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
@targos targos mentioned this pull request May 2, 2022
juanarbol pushed a commit that referenced this pull request May 31, 2022
Fixes: #42860

PR-URL: #42881
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
danielleadams pushed a commit that referenced this pull request Jun 27, 2022
Fixes: #42860

PR-URL: #42881
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
targos pushed a commit that referenced this pull request Jul 12, 2022
Fixes: #42860

PR-URL: #42881
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
targos pushed a commit that referenced this pull request Jul 31, 2022
Fixes: #42860

PR-URL: #42881
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
guangwong pushed a commit to noslate-project/node that referenced this pull request Oct 10, 2022
Fixes: nodejs/node#42860

PR-URL: nodejs/node#42881
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
github-merge-queue bot pushed a commit to yarnpkg/berry that referenced this pull request Jun 1, 2023
**What's the problem this PR addresses?**

The test added in #5362 doesn't run
on Node.js v17.

Fixes
https://github.com/yarnpkg/berry/actions/runs/5060283241/jobs/9083017466

**How did you fix it?**

Updated the range to match Node.js versions containing
nodejs/node#42881

**Checklist**
- [x] I have read the [Contributing
Guide](https://yarnpkg.com/advanced/contributing).
- [x] I have set the packages that need to be released for my changes to
be effective.
- [x] I will check that all automated PR checks pass before the PR gets
reviewed.
github-merge-queue bot pushed a commit to yarnpkg/berry that referenced this pull request Jun 1, 2023
**What's the problem this PR addresses?**

The test added in #5362 doesn't run
on Node.js v17.

Fixes
https://github.com/yarnpkg/berry/actions/runs/5060283241/jobs/9083017466

**How did you fix it?**

Updated the range to match Node.js versions containing
nodejs/node#42881

**Checklist**
- [x] I have read the [Contributing
Guide](https://yarnpkg.com/advanced/contributing).
- [x] I have set the packages that need to be released for my changes to
be effective.
- [x] I will check that all automated PR checks pass before the PR gets
reviewed.
github-merge-queue bot pushed a commit to yarnpkg/berry that referenced this pull request Jun 1, 2023
**What's the problem this PR addresses?**

The test added in #5362 doesn't run
on Node.js v17.

Fixes
https://github.com/yarnpkg/berry/actions/runs/5060283241/jobs/9083017466

**How did you fix it?**

Updated the range to match Node.js versions containing
nodejs/node#42881

**Checklist**
- [x] I have read the [Contributing
Guide](https://yarnpkg.com/advanced/contributing).
- [x] I have set the packages that need to be released for my changes to
be effective.
- [x] I will check that all automated PR checks pass before the PR gets
reviewed.
arcanis pushed a commit to yarnpkg/berry that referenced this pull request Jun 1, 2023
**What's the problem this PR addresses?**

The test added in #5362 doesn't run
on Node.js v17.

Fixes
https://github.com/yarnpkg/berry/actions/runs/5060283241/jobs/9083017466

**How did you fix it?**

Updated the range to match Node.js versions containing
nodejs/node#42881

**Checklist**
- [x] I have read the [Contributing
Guide](https://yarnpkg.com/advanced/contributing).
- [x] I have set the packages that need to be released for my changes to
be effective.
- [x] I will check that all automated PR checks pass before the PR gets
reviewed.
merceyz added a commit to yarnpkg/berry that referenced this pull request Jun 1, 2023
**What's the problem this PR addresses?**

The test added in #5362 doesn't run
on Node.js v17.

Fixes
https://github.com/yarnpkg/berry/actions/runs/5060283241/jobs/9083017466

**How did you fix it?**

Updated the range to match Node.js versions containing
nodejs/node#42881

**Checklist**
- [x] I have read the [Contributing
Guide](https://yarnpkg.com/advanced/contributing).
- [x] I have set the packages that need to be released for my changes to
be effective.
- [x] I will check that all automated PR checks pass before the PR gets
reviewed.
arcanis pushed a commit to yarnpkg/example-repo-zipn that referenced this pull request Jul 3, 2023
**What's the problem this PR addresses?**

The test added in yarnpkg/berry#5362 doesn't run
on Node.js v17.

Fixes
https://github.com/yarnpkg/berry/actions/runs/5060283241/jobs/9083017466

**How did you fix it?**

Updated the range to match Node.js versions containing
nodejs/node#42881

**Checklist**
- [x] I have read the [Contributing
Guide](https://yarnpkg.com/advanced/contributing).
- [x] I have set the packages that need to be released for my changes to
be effective.
- [x] I will check that all automated PR checks pass before the PR gets
reviewed.
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. esm Issues and PRs related to the ECMAScript Modules implementation. needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

regression file:/// import within a data: url no longer works
5 participants