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

ability to fetch file:// URLs in node fetch. #48554

Closed
trusktr opened this issue Jun 26, 2023 · 2 comments
Closed

ability to fetch file:// URLs in node fetch. #48554

trusktr opened this issue Jun 26, 2023 · 2 comments
Labels
duplicate Issues and PRs that are duplicates of other issues or PRs. feature request Issues that request new features to be added to Node.js.

Comments

@trusktr
Copy link
Contributor

trusktr commented Jun 26, 2023

What is the problem this feature will solve?

This makes working with standards easier on the server side. Currently, API such as import.meta.url return a file protocol URL. F.e. file:///path/to/foo.js.

Considering that import standard causes Node.js to return file:// URLs, it is easy to want to do this:

import fs from 'fs'
const relative = path => new URL(path, import.meta.url).href
const path = relative('../some/relative/file.txt')
fs.readFileSync(path) // ---------> ERROR!
// or
await fetch(path) // ----------> ERROR!

When not on the web (f.e. in Node.js, not supporting file:// for security reasons seems to be moot, see node-fetch/node-fetch#75).

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

It would make people's lives easier if they could simply follow standards in Node.js in a way similar to browser code, and the following would just work:

const path = new URL('../some/relative/file.txt', import.meta.url).href
const text  = await fetch(path).then(r => r.text()) // Should just work.

What alternatives have you considered?

n/a

@trusktr trusktr added the feature request Issues that request new features to be added to Node.js. label Jun 26, 2023
@trusktr trusktr changed the title Add the ability to fetch file:// URLs in node fetch. ability to fetch file:// URLs in node fetch. Jun 26, 2023
@bnoordhuis
Copy link
Member

See #45798 (of which this issue is basically a duplicate although you're forgiven for not finding it with github's terrible search) and this #45798 (comment) in particular.

To summarize: the interaction between fetch() and file:// urls is currently underspecced and therefore difficult to implement safely and in a way where we don't paint ourselves in a corner later on.

@bnoordhuis bnoordhuis added the duplicate Issues and PRs that are duplicates of other issues or PRs. label Jun 27, 2023
@bnoordhuis bnoordhuis closed this as not planned Won't fix, can't repro, duplicate, stale Jun 27, 2023
@Artoria2e5
Copy link

The more spec, though admittedly more roundabout way is to go through a blob: URI. See #45188 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate Issues and PRs that are duplicates of other issues or PRs. feature request Issues that request new features to be added to Node.js.
Projects
None yet
Development

No branches or pull requests

3 participants