import.meta

You’re reading the English version of this content since no translation exists yet for this locale. Help us translate this article!

The import.meta object exposes context-specific metadata to a JavaScript module. It contains information about the module, like the module's URL.

Syntax

import.meta

Description

The syntax consists of the keyword import, a dot, and the identifier meta. Normally the left-hand side of the dot is the object on which property access is performed, but here import is not really an object.

The import.meta object is created by the ECMAScript implementation, with a null prototype. The object is extensible, and its properties are writable, configurable, and enumerable.

Examples

Given a module my-module.js

<script type="module" src="my-module.js"></script>

you can access meta information about the module using the import.meta object.

console.log(import.meta); // { url: "file:///home/user/my-module.js" }

It returns an object with a url property indicating the base URL of the module. This will either be the URL from which the script was obtained, for external scripts, or the document base URL of the containing document, for inline scripts.

Specifications

Specification Status Comment
import.meta proposal Stage 3 Initial definition
HTML Living Standard
The definition of 'import.meta' in that specification.
Living Standard Defines import.meta properties in HTML.

Browser compatibility

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
import.metaChrome Full support 64Edge No support NoFirefox Full support 62IE No support NoOpera Full support 51Safari Full support 11.1WebView Android Full support 64Chrome Android Full support 64Firefox Android Full support 62Opera Android Full support 47Safari iOS Full support 12Samsung Internet Android Full support 9.0nodejs ?

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown

Implementation Progress

The following table provides a daily implementation status for this feature, because this feature has not yet reached cross-browser stability. The data is generated by running the relevant feature tests in Test262, the standard test suite of JavaScript, in the nightly build, or latest release of each browser's JavaScript engine.

See also