Theimport.meta
object is a meta-property exposing context-specific meta data to a JavaScript module. It contains information about the module, like the module's URL.
import.meta
The import.meta
object consists of the keyword import
, a dot, and a property name meta
. Normally import.
serves as the context for a property access, 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.
Given a module my-module.js
<script type="module" src="my-module.js"></script>
you can can access meta information about the module using the import.meta
object.
console.log(import.meta); // { url: "file:///home/user/my-module.mjs" }
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.
Specification | Status | Comment |
---|---|---|
import.meta proposal | Stage 3 | |
HTML Living Standard The definition of 'import.meta' in that specification. | Living Standard | Defines import.meta properties in HTML. |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | 64 | ? | 62 | No | 51 | ? |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | 64 | 64 | ? | 62 | 51 | ? | No |
Server | |
---|---|
Node.js | |
Basic support | ? |
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import.meta