← Back to release summary
import.meta.resolve()
- Category
- JavaScript
- Type
- Chromium catches up
- Status
- Enabled by default (Chrome 105)
- Intent stage
- Shipped
Summary
import.meta.resolve(specifier) returns the URL to which the given specifier would resolve in the context of the current script. That is, it returns the URL that would be imported if you did import(specifier).
Motivation
import.meta.resolve() makes it easier to write scripts which are not sensitive to their exact location, or to the web application's module setup. Some of its capabilities are doable today, in a longer form, by combining new URL() and the existing import.meta.url API. But the integration with import maps is novel and allows the new capability of resolving URLs that are affected by import maps.
Standards & signals
- Specification: https://html.spec.whatwg.org/#hostgetimportmetaproperties
- Firefox: Positive
- Safari: Support
- Web developers: Mixed signals — In general web developers are positive on this addition. It is fulfilling a long-standing feature request and closing a gap with non-browser module systems.
The Node.js core team has given negative signals as the synchronous import.meta.resolve() in the HTML Standard conflicts with their asynchronous import.meta.resolve(). See https://gist.github.com/domenic/f2a0a9cb62d499bcc4d12aebd1c255ab#sync-vs-async for a summary of that debate and links discussing Node's plans to align with the HTML Standard going forward.
- Tracking bug: https://bugs.chromium.org/p/chromium/issues/detail?id=1296665
Explainers: https://gist.github.com/domenic/f2a0a9cb62d499bcc4d12aebd1c255ab
View on chromestatus.com