import.meta

Syntax

Value

There’s two distinct import.meta objects: The object that is referenced in source files and the object that exists when running the application. Since the value is specific to individual files, references to import.meta are typically replaced during bundling.

For authoring code, bundlers may provide the following properties:

url
A reference to the current module that can be used to reference other resources. Often used in combination with the URL constructor.
resolve
Resolves a given specifier in the context of the current file. Very similar to url but more concise for common use cases.
hot Experimental
During development, this may be an object that provides APIs for handling hot replacement. The details of the API are bundler specific.
env Experimental
Object that contains custom environment settings, e.g. those read from .env files.
env.DEV and env.PROD Experimental

env.DEV is a boolean that specifies if development-time debug assertions should be enabled, e.g. because the code is running in an interactive development environment. It’s opposite is env.PROD which should always be equal to !env.DEV.

env.MODE Experimental
A string description for a “bundling mode”. May include any user-defined string.
env.SSR Experimental
A boolean that is true if the code is running as part of SSR (server-side rendering).
webpack, webpackHot, and webpackContext Experimental
The major version of webpack used to bundle, webpack’s hot module replacement API for this module, and contextual information about how this module was included in the current webpack build.

Specifications

Specification
MDN
https://developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/import.meta
vite.dev
https://vite.dev/guide/env-and-mode
webpack.js.org
https://webpack.js.org/api/module-variables/#importmeta

Bundler compatibility

BundlersRuntimes
esbuild
Rsbuild
Rspack
Vite
Webpack
Bun
Deno
Node.js
import.meta
import.meta.url
Worker from import.meta.url
import⁠.meta.resolve
import⁠.meta.envExperimental
import⁠.meta.env?.XExperimental
import⁠.meta.hotExperimental
import⁠.meta.webpack*Experimental