What Gets Auto-Imported?
Nuxt automatically imports:- Components from
app/components/ - Composables from
app/composables/ - Utilities from
app/utils/ - Vue APIs like
ref,computed,watch, etc. - Nuxt composables like
useFetch,useRoute,useState, etc.
app/app.vue
In the docs, every function that is not explicitly imported is auto-imported by Nuxt and can be used as-is in your code.
Benefits of Auto-Imports
- Less boilerplate - No need to write import statements
- Type safety - Full TypeScript support and IntelliSense
- Tree-shaking - Only includes what’s used in production
- Better DX - Focus on building features, not managing imports
Built-in Auto-Imports
Nuxt auto-imports functions and composables to perform data fetching, get access to the app context and runtime config, manage state, or define components and plugins.ref or computed, as well as lifecycle hooks and helpers that are auto-imported by Nuxt.
Directory-Based Auto-Imports
Nuxt directly auto-imports files created in defined directories:app/components/for Vue componentsapp/composables/for Vue composablesapp/utils/for helper functions and other utilities
Components Auto-Import
Components inapp/components/ are automatically imported and available throughout your application:
app/components/AppButton.vue
app/app.vue
Composables Auto-Import
Composables inapp/composables/ are automatically available:
app/composables/useCounter.ts
app/app.vue
Utils Auto-Import
Utility functions inapp/utils/ are automatically available:
app/utils/format.ts
app/app.vue
Context Awareness
When using built-in Composition API composables provided by Vue and Nuxt, be aware that many rely on being called in the right context. During a component lifecycle, Vue tracks the temporary instance of the current component (and similarly, Nuxt tracks a temporary instance ofnuxtApp) via a global variable, and then unsets it in the same tick. This is essential when server rendering to avoid cross-request state pollution.
You must use composables synchronously - you cannot use await before calling a composable, except within:
<script setup>blockssetup()function of components declared withdefineNuxtComponentdefineNuxtPlugindefineNuxtRouteMiddleware
composables/example.ts
composables/example.ts
Explicit Imports
Nuxt exposes every auto-import with the#imports alias that can be used to make the import explicit if needed:
- You need to be explicit for clarity
- You want to avoid naming conflicts
- You’re working with tools that don’t understand auto-imports
Disabling Auto-Imports
If you want to disable auto-importing composables and utilities, you can setimports.autoImport to false in the nuxt.config file.
nuxt.config.ts
#imports.
Partially Disabling Auto-Imports
If you want framework-specific functions likeref to remain auto-imported but wish to disable auto-imports for your own code, you can set imports.scan to false:
nuxt.config.ts
- Framework functions like
ref,computed, orwatchwill still work without manual imports - Custom composables and utilities need to be manually imported
Auto-Importing from Third-Party Packages
Nuxt allows auto-importing from third-party packages. For example, you could enable auto-import of theuseI18n composable from the vue-i18n package:
nuxt.config.ts
Best Practices
- Use auto-imports - They’re optimized and type-safe
- Organize by directory - Put files in the correct directory for auto-import
- Name exports carefully - Avoid naming conflicts
- Use TypeScript - Get full type safety and IntelliSense
- Be aware of context - Understand when and where composables can be called