When to use
- The app runs Vue 2 (EOL 31 Dec 2023) and the user wants to move to Vue 3.
- For Nuxt 2 apps, use the Nuxt path in
legacy/vue2-nuxt2instead (Nuxt Bridge or a rebuild); this skill covers Vue apps built with Vite, Vue CLI or webpack.
Before you start
- Read
vue,vue-template-compiler,vue-router,vuex,@vue/test-utils, the build tool (Vue CLI, webpack, Vite) and every Vue plugin and UI library from the lockfile. - For each library, find a Vue 3 version or a replacement (for example Vuetify 2 → 3, BootstrapVue → a Vue 3 alternative,
vue-i18n8 → 9+). Libraries without a Vue 3 path are the main blockers; list them for the user. - Working tree clean; new branch (
chore/vue-3); a test suite and E2E smoke tests for main flows (add them first if missing). - Ask the user:
- whether to migrate the build tool (Vue CLI → Vite) in the same project, as a separate step before or after;
- Vuex → Pinia now, or Vuex 4 first;
- whether network installs are approved (
core/supply-chaincooldown applies).
Steps
- Baseline: install, lint, unit tests, E2E and a production build. Record failures.
- Move to Vue 2.7 (
vue@2.7), remove@vue/composition-apiif present, and fix deprecation warnings. 2.7 lets you start writing<script setup>and Composition API code that also works in Vue 3. - Remove patterns the compat build can't cover well while still on Vue 2: filters → methods or computed; event bus (
$on/$off/$once) → a tiny emitter (mitt) or Pinia;$children→ refs;.nativemodifiers → explicitemits; functional components with templates → plain components. - Switch to Vue 3 + compat build:
- install
vue@^3.5and@vue/compat@^3.5(same version) and@vue/compiler-sfc(removevue-template-compiler); - alias
vueto@vue/compatin the bundler and set the compiler'scompatConfig: { MODE: 2 }(Vite:resolve.aliasplus@vitejs/plugin-vuetemplate.compilerOptions.compatConfig; Vue CLI:chainWebpackalias andvue-loaderoptions); - update
vue-routerto v4+ API (createRouter,createWebHistory) and Vuex to 4 (createStore) or Pinia; - replace
new Vue({...})withcreateApp(App).use(router).use(store).mount('#app').
- install
- Run the app and fix compat warnings feature by feature. Each warning names a compat flag (for example
COMPONENT_V_MODEL,INSTANCE_LISTENERS,RENDER_FUNCTION,ATTR_FALSE_VALUE,TRANSITION_CLASSES). Fix the code, then disable that flag per component (compatConfig: { COMPONENT_V_MODEL: false }) or globally (configureCompat). Typical fixes:v-modelon components:value/input→modelValue/update:modelValue(ordefineModel);$listenersmerged into$attrs;inheritAttrsbehavior withclass/style;v-if/v-forprecedence changed;keyon<template v-for>;- async components →
defineAsyncComponent; - transition class renames (
v-enter→v-enter-from); - global API (
Vue.use,Vue.component,Vue.prototype) → app instance (app.use,app.component,app.config.globalProperties).
- Update tests:
@vue/test-utilsv2 (mountoptions changed:props,global.plugins,global.stubs). - Remove the compat build when no warnings remain: drop the alias and
@vue/compat, setMODE: 3or removecompatConfig, and run everything again. Then switch tofrontend/vue. - Show the diff and results at each step and wait for approval; commit only when asked (
git-commitskill).
Verify
npm ci
npm ls vue @vue/compat vue-router vuex pinia # one Vue version; @vue/compat gone at the end
npx vue-tsc --noEmit # TypeScript projects
npm run lint
npm test
npm run build
npm audit --audit-level=moderate
Then run the E2E suite and click through the main flows with the browser console open: no compat warnings, no Vue warnings, forms and v-model bindings work, router navigation and guards behave as before.
Safety
- Never remove the compat build while warnings remain; never globally disable compat flags you haven't fixed.
- Never upgrade a UI library major and Vue in the same step without telling the user; keep each step reviewable.
- Never ship the full template compiler build to production after the migration.
- Never auto-commit, push or deploy; don't hand-edit the lockfile.