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
URLconstructor. resolve- Resolves a given specifier in the context of the current file. Very similar to
urlbut more concise for common use cases. hotExperimental- During development, this may be an object that provides APIs for handling hot replacement. The details of the API are bundler specific.
envExperimental- Object that contains custom environment settings, e.g. those read from
.envfiles. env.DEVandenv.PRODExperimentalenv.DEVis 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 isenv.PRODwhich should always be equal to!env.DEV.env.MODEExperimental- A string description for a “bundling mode”. May include any user-defined string.
env.SSRExperimental- A boolean that is true if the code is running as part of SSR (server-side rendering).
webpack,webpackHot, andwebpackContextExperimental- 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
Bundler compatibility
| Bundlers | Runtimes | |||||||
|---|---|---|---|---|---|---|---|---|
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 | ||||||||