-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
Support import.meta.resolve(…)
#14500
Comments
Recently I wrote down some thoughts: #14405 IMO it'd be nice to implement this as a plugin first before including it to the core. |
ooooh, glad to see it! 🤩
That does look like that's been a good prototyping path in the past! For what it's worth, as a library author I have two main concerns:
Now that I'd also be happy help author a plugin or a PR if it helps, but unfortunately I wouldn't be able to commit any time to ongoing maintenance. |
@sapphi-red I would have to agree with @lgarron on this one. This is core language feature. And the benefits of including |
I drafted a PR for this by adapting
Also, #11823 is rather funny. 😄 I could use suggestions on a path forward. |
Description
Vite and other bundlers support using
new URL("path", import.meta.url)
to resolve relative paths.This was a useful convention for a while, but now we have
import.meta.resolve(…)
to express a relative path resolution.It is supported by all major browsers and all major runtimes.
Suggested solution
Recognize and transpile
import.meta.resolve(…)
as part of the import graph. It would be pretty similar to dynamicimport(…)
but without actually importing code.import.meta.resolve(…)
(just transform the argument).new URL(…, import.meta.url)
.import.meta.resolve(…)
is not an ECMAScript feature, but I would recommend classifying it as ES2022 or ES2023 since all major browsers and runtimes landed support over the last year.Alternative
The existing
new URL(…, import.meta.url)
support could be considered sufficient. However, this has significant drawbacks for library authors:import.meta.resolve(…)
.import.meta.url
in different ways, which can cause compatibility bugs. It would be nice to avoid the need to publish code thatimport.meta.url
for relative path resolution.new URL(…, import.meta.url)
does not support bare imports. However, some bundlers overload the syntax to allow this. This means thatnew URL("bare-import", import.meta.url)
has two meanings (import a relative file named e.g.bare-import.js
, or import the packagebare-import
), which means that a library install can break unrelated working code due to ambiguity.import.meta.resolve(…)
supports package (or import map) paths without ambiguity.Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: