Registry / web-framework / vant
library4.9.24jsnpmunverified

Vant is a lightweight and highly customizable UI component library designed for mobile web applications built with Vue.js. The current stable version series is 4.x, specifically 4.9.24 for Vue 3 projects, while Vant 2.x (e.g., 2.13.9) continues to support Vue 2. The library maintains an active release cadence, frequently adding new features, bug fixes, and improvements within its major versions. Key differentiators include its small bundle size (1KB average per component min+gzip), over 80 high-quality components, zero third-party dependencies, strong TypeScript support, extensive documentation, and comprehensive feature set including tree-shaking, custom themes, accessibility, dark mode, SSR, and i18n with 30+ built-in languages. It also provides dedicated modules for Nuxt 2 and Nuxt 3.

npm install vant
INSTALL
IMPORT
SIG · VANT
V
vant
web-frameworkjavascriptv4.9.24
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Button
import { Button } from 'vant';
import Button from 'vant/es/button'; // Older, less common, or direct import if not using tree-shaking setup const Button = require('vant').Button; // CommonJS is not the primary way for Vue components, especially with tree-shaking
Vant supports tree-shaking, so named imports are recommended. Manual import of specific components is also possible, but `vant` exports components directly for convenience.
CSS Styles
import 'vant/lib/index.css';
import 'vant/es/index.css'; // Incorrect path for modern Vant 4 import 'vant/lib/index.less'; // If using Less, requires pre-processing import 'vant/lib/index.scss'; // If using Sass, requires pre-processing
The core CSS styles are crucial for Vant components to render correctly. This import should be placed globally or at the root of your application. Ensure your build tool handles CSS imports.
Locale
import { Locale } from 'vant'; Locale.use('en-US');
import { useLocale } from 'vant'; // Incorrect hook name for global locale config
For global locale configuration, import `Locale` and use its `use` method. This sets the language for all Vant components.

This quickstart demonstrates how to set up a basic Vue 3 application, import Vant components (Button, Toast), register them globally, and include the necessary CSS styles to render a functional Vant button and show a toast message.

import { createApp } from 'vue'; import { Button, Toast } from 'vant'; import 'vant/lib/index.css'; const app = createApp({ template: ` <van-button type="primary" @click="showToast">Click me</van-button> `, methods: { showToast() { Toast('Hello Vant!'); } } }); app.use(Button); app.use(Toast); app.mount('#app');
Debug
Known issues
breakingVant 3.x and 4.x are designed for Vue 3. Migrating from Vant 2.x (Vue 2) to Vant 3.x/4.x requires upgrading your Vue project to Vue 3, which involves significant breaking changes in Vue itself.
fix
For Vue 3 projects, use `npm i vant`. For Vue 2 projects, use `npm i vant@latest-v2`. Review the official Vant 3/4 migration guide and Vue 3 migration guide for detailed steps.
affects: >=3.0.0
gotchaForgetting to import the global Vant CSS file (`vant/lib/index.css`) will result in components rendering without any styling, appearing as plain HTML elements.
fix
Ensure `import 'vant/lib/index.css';` is included in your main application entry file (e.g., `main.js`/`main.ts`) or a global style entry point. If using a CSS preprocessor, you might need to import the `.less` or `.scss` variant and configure your build.
affects: >=2.0.0
gotchaWhen using on-demand import (e.g., with `unplugin-vue-components` or `vite-plugin-components`), ensure the Vant resolver is correctly configured, otherwise components might not be automatically imported or their styles may be missing.
fix
Refer to the Vant documentation for the specific auto-import resolver (e.g., `@vant/auto-import-resolver`) and its configuration in your build tool (Vite, Webpack, etc.). Often, a post-processor like PostCSS is also required for proper theme customization and unit conversion.
affects: >=3.0.0
deprecatedOlder versions of Vant might have exposed components directly via `vant/es/{componentName}`, but the recommended and tree-shakable way is to use named imports from the main `vant` package.
fix
Always use `import { ComponentName } from 'vant';` for individual components to leverage tree-shaking effectively. If you are using a bundler with proper configuration (e.g., Vite), this should work out of the box.
affects: <4.0.0
gotchaVant components are designed for mobile environments. Using them directly in desktop browsers might lead to unexpected layout or interaction issues without `vant-touch-emulator` or proper desktop styling.
fix
For desktop development or testing, consider installing and importing `vant-touch-emulator` to simulate touch events. For production desktop apps, consider a different UI library or extensive custom styling for Vant components.
affects: >=2.0.0
Errors
Common errors & fixes
Error: Failed to resolve component: van-button
Vant component was used in a Vue template but not registered with the Vue app.
fix
Ensure all Vant components used in templates are explicitly registered with your Vue application instance via `app.use(ComponentName);` or are automatically imported through a build tool plugin.
TypeError: Cannot read properties of undefined (reading 'use')
Attempting to use `app.use()` on a Vant component that is not a plugin or trying to access a method on an undefined Vant export.
fix
Verify the correct import path and ensure the symbol being used is indeed a Vue plugin (e.g., `Button` is not a plugin directly, but a component. `Toast` or `Dialog` can be installed as plugins or used via their API methods after importing their functions).
Uncaught SyntaxError: Cannot use import statement outside a module
Attempting to use ES module `import` syntax in an environment that expects CommonJS (e.g., Node.js script without `--experimental-modules` or misconfigured Webpack/Rollup).
fix
Ensure your project is configured for ES modules, typically by setting `"type": "module"` in `package.json` or by using a modern bundler like Vite/Webpack configured for ESM output. If targeting an older Node.js environment, consider a transpilation step.
Upgrade
Version history
4.9.24latest on npm
Audit
Dependencies
vuerequiredVant components are built on Vue and require Vue 3.x for Vant 4.x, or Vue 2.x for Vant 2.x.
Agent activity
9 hits · last 30 days
node
8
Resources