FrontendDeveloper.in

ECMAScript Track Detail

import.meta

The import.meta object was created by the ECMAScript implementation with a null prototype to get context-specific metadata about a JavaScript module. Let's say you are trying to load my-module from a script,

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

Now you can access meta information(base URL of the module) about the module using the import.meta object

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

The above URL can be either URL from which the script was obtained (for external scripts), or the document base URL of the containing document (for inline scripts).

Note: Remember import is not really an object but import.meta is provided as an object which is extensible, and its properties are writeable, configurable, and enumerable.