Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Vue 3 debugging reference for reactivity issues, computed errors, watcher bugs, async failures, and SSR hydration problems.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
reference/plugin-install-before-mount.md
1# Install Plugins Before Mounting the App23## Rule45All plugins must be installed using `app.use()` BEFORE calling `app.mount()`. Installing plugins after the app is mounted can lead to reactivity issues, missing dependencies, and unexpected behavior.67## Why This Matters891. **Hidden dependencies**: Components may render before plugins they depend on are available, causing runtime errors.10112. **Reactivity issues**: Late plugin installation can cause subtle reactivity problems where provided values aren't properly reactive.12133. **Initialization order**: Many plugins (like vue-router, pinia) need to set up state before any component renders.14154. **Ecosystem complexity**: Adding plugins after mount can cause issues with Vue's internal ecosystem and hydration in SSR scenarios.1617## Bad Practice1819```typescript20import { createApp } from 'vue'21import App from './App.vue'22import router from './router'23import i18nPlugin from './plugins/i18n'2425const app = createApp(App)2627// Mounting first - plugins not yet available!28app.mount('#app')2930// Installing after mount - TOO LATE!31app.use(router)32app.use(i18nPlugin, { locale: 'en' })33```3435## Good Practice3637```typescript38import { createApp } from 'vue'39import App from './App.vue'40import router from './router'41import { createPinia } from 'pinia'42import i18nPlugin from './plugins/i18n'4344const app = createApp(App)4546// Install all plugins BEFORE mounting47app.use(createPinia())48app.use(router)49app.use(i18nPlugin, { locale: 'en' })5051// Mount LAST52app.mount('#app')53```5455## Plugin Installation Order5657The order of `app.use()` calls can matter when plugins depend on each other:5859```typescript60const app = createApp(App)6162// 1. State management first (other plugins might need it)63app.use(createPinia())6465// 2. Router (may depend on state)66app.use(router)6768// 3. Other plugins (may depend on router or state)69app.use(authPlugin)70app.use(i18nPlugin, { locale: 'en' })7172// 4. Mount last73app.mount('#app')74```7576## Async Plugin Installation7778If you need to perform async operations before mounting:7980```typescript81import { createApp } from 'vue'82import App from './App.vue'83import { loadPlugins } from './plugins'8485async function bootstrap() {86const app = createApp(App)8788// Await async plugin setup89const i18nPlugin = await loadI18nMessages()9091// Install all plugins92app.use(i18nPlugin)9394// Mount after everything is ready95app.mount('#app')96}9798bootstrap()99```100101## Duplicate Installation Protection102103Vue's `app.use()` automatically prevents duplicate plugin installation:104105```typescript106app.use(myPlugin)107app.use(myPlugin) // This second call is ignored - no double installation108109// This is handled internally by Vue, providing a safety net110```111112## Common Symptoms of Late Plugin Installation113114- `inject()` returns `undefined` unexpectedly115- Router navigation guards not firing116- Store state not reactive117- Template errors about undefined global properties118- Hydration mismatches in SSR119120## References121122- [Vue.js Plugins Documentation](https://vuejs.org/guide/reusability/plugins.html)123- [Vue.js Application API](https://vuejs.org/api/application.html)124- [Vue 3 Migration Guide - Global API](https://v3-migration.vuejs.org/breaking-changes/global-api.html)125