Skip to content

Can the intent and correct use of import.meta be clarified further? #3539

Open
@jasnell

Description

@jasnell

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 and import.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 use import.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 of import.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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions