← 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

Explainers: https://gist.github.com/domenic/f2a0a9cb62d499bcc4d12aebd1c255ab

View on chromestatus.com