Vue Components Auto-Importer
unplugin-vue-components is an unplugin-powered build tool plugin that provides on-demand auto-importing for Vue 3 components and directives. It eliminates the need for manual `import` statements and component registrations, simplifying development workflows and enabling automatic code-splitting for asynchronously loaded parent components. The current stable version is 32.0.0, released in April 2026. The project maintains a frequent release cadence, with minor and patch versions released regularly (often weekly or bi-weekly) and major versions introducing breaking changes every few months. Its key differentiators include broad build tool support (Vite, Webpack, Rollup, Rolldown, esbuild, Rspack) via the `unplugin` ecosystem, tree-shakability, built-in resolvers for popular UI libraries, folder-based namespaces, and full TypeScript support, including generated type declarations. It also integrates well with `unplugin-icons` for icon auto-importing.
Common errors
-
Error [ERR_REQUIRE_ESM]: require() of ES Module ... is not supported. Instead change the require of ... to a dynamic import() or change the configuration to enable ESM.
cause Attempting to `require()` `unplugin-vue-components` (or its build tool specific entry points) in a CommonJS context after v31.0.0, when the package became ESM-only.fixUpdate your build configuration file (e.g., `webpack.config.js`, `rollup.config.js`) to use ESM `import` statements or dynamic `import()`. For Webpack, consider renaming your config file to `webpack.config.mjs`. -
TypeError [ERR_INVALID_ARG_TYPE]: The 'path' argument must be of type string. Received undefined
cause This generic error can occur if the `Components` plugin is called without a valid configuration object or if a resolver is misconfigured, leading to internal path resolution issues. Often related to missing `dts` option or incorrect `dirs` path.fixEnsure the `Components` plugin is called with an object `Components({ /* options */ })` and that `dts: true` is set if you rely on type generation. Double-check all resolver configurations and component directories for correctness. -
Error: Node.js version 16.x.x is not supported. Please upgrade to Node.js 20.19.0 or higher.
cause Running `unplugin-vue-components` version 31.0.0 or higher on an unsupported Node.js version.fixUpgrade your Node.js environment to version 20.19.0 or newer. Use a Node.js version manager like `nvm` to switch versions if needed.
Warnings
- breaking Version 32.0.0 upgrades the underlying `unplugin` dependency to v3. This might introduce breaking changes or require adjustments if you are using advanced `unplugin` features or custom plugins that rely on older `unplugin` APIs.
- breaking Since version 31.0.0, `unplugin-vue-components` has moved to ESM-only. CommonJS `require()` statements are no longer supported directly. This impacts how the plugin is imported in build tool configuration files, especially for Webpack and Rspack setups which traditionally use CommonJS.
- breaking Version 31.0.0 drops support for Node.js versions older than 20.19.0. Running the plugin with an unsupported Node.js version will lead to errors.
- breaking Version 31.0.0 removes support for Vue 2 and the associated `element-ui` resolver. If your project still uses Vue 2 or relies on `element-ui` auto-importing, this version is not compatible.
- breaking Version 29.0.0 upgrades the peer dependency `@nuxt/kit` to v4. This is a breaking change for Nuxt users who are not yet on Nuxt 4 or compatible `@nuxt/kit` versions.
- gotcha If you are using Nuxt, you might not need `unplugin-vue-components` directly. Nuxt provides its own component auto-importing feature via `@nuxt/components`, which is often preferred for deeper integration within the Nuxt ecosystem.
Install
-
npm install unplugin-vue-components -
yarn add unplugin-vue-components -
pnpm add unplugin-vue-components
Imports
- Components
const Components = require('unplugin-vue-components/vite')import Components from 'unplugin-vue-components/vite'
- Components
const Components = require('unplugin-vue-components/rollup')import Components from 'unplugin-vue-components/rollup'
- Components
const Components = require('unplugin-vue-components/webpack')import Components from 'unplugin-vue-components/webpack'
- ElementPlusResolver
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
Quickstart
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import Components from 'unplugin-vue-components/vite';
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
export default defineConfig({
plugins: [
vue(),
Components({
// Specify a path to automatically scan components (e.g., your local `src/components` folder)
dirs: ['src/components'],
// Automatically register components from popular UI libraries using resolvers
resolvers: [
ElementPlusResolver(), // Example: auto-import Element Plus components
// Add other resolvers as needed, e.g., AntDesignVueResolver(), VantResolver(), etc.
],
// Generate `components.d.ts` global type declarations for TypeScript support
dts: true,
// Allow use of `defineOptions` and `defineModels` within components (Vue 3.3+)
allowAsProps: true,
// Custom transformers (e.g., for custom directives or specific component patterns)
transformers: [],
// Filter for files that should be processed by the plugin
include: [/\.vue$/, /\u005c.vue\u005c?vue/],
// Exclude files/directories to avoid processing (e.g., node_modules, build outputs)
exclude: [/[\\/]node_modules[\\/]/, /[\\/]\u005c.git[\\/]/, /[\\/]\u005c.nuxt[\\/]/]
})
]
});