During my setup Vue and Vite in my project, I came across a very common problem: @vitejs/plugin-vue requires vue (>=3.2.13) or @vue/compiler-sfc to be present in the dependency tree.
I have solved this isseu for my project and let me tell you that this error is not new and very obivous error that any developer can face.
So I decide to share my experince to other developers also, here are the ways to solve it based on my experience and research, so if you are also facing this problem, then this guide will be helpful for you.
Cause of the problem
Let's first understand why this issue occurs, this problem occurs when Vite's Vue plugin requires vue (at least version 3.2.13) or @vue/compiler-sfc in your project's dependency tree.
So If the correct version is not present in your project or the correct dependency is not installed for some reason, then this error occurs, so it is very important to check the correct version first.
npm install vue@^3.2.13 npm install @vue/compiler-sfc --save-dev
{ "dependencies": { "vue": "^3.2.13" }, "devDependencies": { "@vue/compiler-sfc": "^3.2.13" } }
npm install @vitejs/plugin-vue --save-dev
rm -rf node_modules rm package-lock.json npm cache clean --force npm install
import { defineConfig } from 'vite'; import vue from '@vitejs/plugin-vue'; export default defineConfig({ plugins: [vue()] });