-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Can the intent and correct use of import.meta be clarified further? #3539
Comments
In particular, I think it would be reasonable to make a normative requirement that anything on import.meta be something specific to that module - and to note that it is not intended as a replacement of globals or environment variables. |
I suppose the ship has sailed to require |
@mhofman that wouldn't address the OP tho, which is to indicate what hosts can put on the object. |
I agree I would be happy if we added a sentence of guidance to the spec to the effect of "values and functions on |
Here is an idea: a requirement that any non-intrinsic object reachable by property crawl from |
That seems useful to me, but is also orthogonal to the goal of the issue. |
Note that freezing was already discussed and rejected: tc39/proposal-import-meta#3 Whatever the direction will end up being, it'd be great if it allowed non-unique functions. For example, function import.meta.resolve(url) {
return new URL(url, this.url);
} doesn't need to be unique per-module, even if it's goal is to provide per-module resolution. |
Fair, I hadn't considered the |
The
import.meta
mechanism was intentionally left wide open for use by the runtimes to introduce contextual information about the module that was imported. Unfortunately, however, the ecosystem is starting to see quite questionable uses that do not really fall into the "contextual information about the module" category.Probably the most visible/prominent such examples are Vite's use of
import.meta.env
andimport.meta.hot
.Prior to its official formation as TC55, WinterCG had taken up a discussion around use of
import.meta
and the possible cross-runtime interop issues that it presents when user code begins to useimport.meta
in whatever way it wants, ignoring the fact that it is a globally shared namespace. We're already seeing some clashes in that namespace as evidence in the import-meta-registry where we have duplicative definitions ofimport.meta.dirname
,import.meta.dir
,import.meta.filename
,import.meta.file
, etc that are used in Node.js, Deno, and Bun.A key concern is that if the ecosystem begins to see
import.meta
as Just Another Open Global Namespace They Can Add Whatever They Want To, we're going to end up with fairly significant interop issues later and increased issues around feature sniffing.Obviously there's not a lot we can do without risking breaking web compat but stronger, clearer language in the spec about what
import.meta
is meant for and whether runtimes (or committees like TC55) are allowed/encouraged to lock it down further would likely be helpful./cc @ljharb
The text was updated successfully, but these errors were encountered: