Import meta
En esta página
The import.meta Object#
With ES modules you can obtain some metadata from the code that imports or compiles your ES-module.
This is done through import.meta, which is an object that provides your code with this information.
Throughout the Nuxt documentation you may see snippets that use this already to figure out whether the
code is currently running on the client or server side.
::read-more{to="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import.meta"}
Read more about import.meta.
::
Runtime (App) Properties#
These values are statically injected and can be used for tree-shaking your runtime code.
::note
process.browser, process.client, process.dev, process.server, and process.test were soft-deprecated in Nuxt 3.12. In Nuxt 5 or with future.compatibilityVersion: 5, Nuxt no longer augments NodeJS.Process with those properties. Prefer the matching import.meta.* flags; build-time process.* defines still exist for compatibility.
::
| Property | Type | Description |
|---|---|---|
import.meta.client |
boolean | True when evaluated on the client side. |
import.meta.browser |
boolean | True when evaluated on the client side. |
import.meta.server |
boolean | True when evaluated on the server side. |
import.meta.nitro |
boolean | True when evaluated on the server side. |
import.meta.dev |
boolean | True when running the Nuxt dev server. |
import.meta.envName :badge[v4.5]{color="info" size="xs" class="align-middle"} |
string | The current Nuxt environment name, including custom values passed via --envName. |
import.meta.test |
boolean | True when running in a test context. |
import.meta.prerender |
boolean | True when rendering HTML on the server in the prerender stage of your build. |
Builder Properties#
These values are available both in modules and in your nuxt.config.
| Property | Type | Description |
|---|---|---|
import.meta.env |
object | Equals process.env |
import.meta.url |
string | Resolvable path for the current file. |
Example#
Using import.meta.url to Resolve Files within Modules#
```ts [modules/my-module/index.ts] import { createResolver } from 'nuxt/kit'
// Resolve relative from the current file const resolver = createResolver(import.meta.url)
export default defineNuxtModule({ meta: { name: 'myModule' }, setup () { addComponent({ name: 'MyModuleComponent', // Resolves to '/modules/my-module/components/MyModuleComponent.vue' filePath: resolver.resolve('./components/MyModuleComponent.vue'), }) }, }) ```