| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
Review requested:
|
Sorry, something went wrong.
|
Thank you for looking into this. This is definitely something that we should improve.
All of the other runtime error messages you cite mention relative URLs. I think a better comparison would be what messages they throw for your example code when an import map is registered that defines that bare import. Do any of them resolve it? |
Sorry, something went wrong.
The Safari one does not.
Import maps are only supported by Chromium and Deno, and yes they do resolve them. oops my testing was flawed, they do support it, let me recheck |
Sorry, something went wrong.
|
If the import map maps bare-package-name to an absolute URL, it resolves it. If the import map maps it to a relative URL, it throws the same error as before. |
Sorry, something went wrong.
Then I think we should do the same, per our own resolution algorithm. That was my expectation when I tried that code; it doesn’t really make sense to me as a user that it should error. Like, import of a bare specifier within a data: URL works, so therefore so should import.meta.resolve. |
Sorry, something went wrong.
|
I don't understand what do you mean. Could you lay down what would be the expected behavior vs the actual behavior? |
Sorry, something went wrong.
|
For this code: import('data:text/javascript,export default import.meta.resolve("pkg")').catch(console.error)Currently this code always errors. Assuming that import('pkg') would resolve, then the above code should no longer error, and import.meta.resolve("pkg") should return the file URL to 'pkg'. |
Sorry, something went wrong.
|
What would it resolve to? |
Sorry, something went wrong.
You're talking about the file URL, but we're in a data URL. How could I link the two? |
Sorry, something went wrong.
I’m not sure, but as a user I expect it to work. Like I assume this works? import('data:text/javascript,import("pkg")')(Assuming that pkg itself exists, that import('pkg') would work in normal non-data: URL code.) If the above works, then we’re already resolving that import somehow, so import.meta.resolve would use the same approach. |
Sorry, something went wrong.
|
It doesn't work, and it cannot work. It's documented in Lines 208 to 213 in e11c7b7 |
Sorry, something went wrong.
Well it cannot work as we’ve currently defined data: URLs, but it can work as we can see browsers doing it via import maps. And maybe that’s the answer for us too, that the current filesystem-based resolution algorithm cannot resolve imports in data: URLs but when we add support for import maps then this begins to work when an import map is loaded. I guess the alternative would be to define the parentURL for data: URLs to be pathToFileURL(process.cwd()), but I’m sure you’ll tell me why that’s a bad idea 😄 Anyway thanks for improving the error messaging, that’s a good improvement for now. |
Sorry, something went wrong.
| is unsupported. Calling `import.meta.resolve` with a relative URL from a `data:` | ||
| module is unsupported. |
There was a problem hiding this comment.
| is unsupported. Calling `import.meta.resolve` with a relative URL from a `data:` | |
| module is unsupported. | |
| is unsupported. Calling `import.meta.resolve` with a relative URL or bare specifier | |
| from a `data:` module is unsupported. |
Right?
Sorry, something went wrong.
There was a problem hiding this comment.
It's already covered by the previous sentence: Calling import.meta.resolve with a bare specifier outside of a file: module is unsupported.
Sorry, something went wrong.
There was a problem hiding this comment.
I find this paragraph very confusing. Maybe it would be clearer if we made it affirmative instead?
- From modules loaded from file: URLs, import.meta.resolve can resolve absolute URLs, relative URLs, and bare specifiers.
- From modules loaded from https: URLs, import.meta.resolve can resolve absolute URLs and relative URLs.
- From modules loaded from data: URLs, import.meta.resolve can resolve only absolute URLs.
Or whatever the correct support matrix is.
Sorry, something went wrong.
The parentURL for data: modules is whatever module loaded that data: module, so changing it wouldn't help – and yes it would break things.
Not really, because we don't have import map support nor anything that looks like it. Worth noting that the same data: URL can be imported from different context (different folder, but even different protocol, e.g. the same data: module can be imported by an HTTP module and a file one). Consider the following: // /root/file.mjs
export {default} from 'data:text/javascript,export {default} from "pkg"';// /root/node_modules/pkg/index.cjs
module.exports=1;// /home/user/file.js
export {default} from 'data:text/javascript,export {default} from "pkg"';// /home/user/node_modules/pkg/index.cjs
module.exports=2;and then you run node --input-type=module -e 'import One from 'file:///root/file.js;import OneAsWell from 'file:///home/user/file.js', it would be very confusing. |
Sorry, something went wrong.
|
I don't really like the name of the error (ERR_UNSUPPORTED_RESOLVE_REQUEST), nor am I happy with the documentation text. Open to suggestions. |
Sorry, something went wrong.
There was a problem hiding this comment.
| 'Failed to resolve module specifier "%s" from "%s": Invalid relative url or base scheme is not hierarchical.', | |
| 'Failed to resolve module specifier "%s" from "%s": Invalid relative URL or unsupported protocol.', |
What does “base scheme is not hierarchical” mean?
Maybe when the protocol is data: just say: import.meta.resolve is not supported within data: URLs ?
Sorry, something went wrong.
There was a problem hiding this comment.
It's not just with data: URLs, however. It's really any non-special URL whose hierarchy semantics cannot be determined. For instance, suppose we supported a hypothetical fake:module URL in the future, this error would also apply in that case since new URL('something', 'fake:module') would end up as an invalid URL error.
One way we could improve the error message is to say something like:
Failed to resolve module specifier "...": import.meta.resolve is not supported with ${baseUrl}
Where ${baseUrl} is the full url of the referring module.
Sorry, something went wrong.
There was a problem hiding this comment.
But import.meta.resolve is supported with data: URLs, just it won't accept relative URLs / bare specifiers. I inspired myself for this error message from Chromium's error message, which might not be perfect, but is probably at least technically correct.
Sorry, something went wrong.
Sorry, something went wrong.
Sorry, something went wrong.
Sorry, something went wrong.
Sorry, something went wrong.
Sorry, something went wrong.
Sorry, something went wrong.
PR-URL: nodejs#49516 Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: #49516 Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: #49516 Reviewed-By: James M Snell <jasnell@gmail.com>
| Back | FazBrowse Home | New Git URL |
Not sure about the error code (ERR_UNSUPPORTED_RESOLVE_REQUEST). For reference, here are what error message other runtimes emit when doing import('data:text/javascript,export default import.meta.resolve("bare-package-name")').catch(console.error):
Here are the error messages for import('data:text/javascript,export default import.meta.resolve("./relative")').catch(console.error):