Error: @vitejs/plugin-vue requires vue (>=3.2.13) or @vue/compiler-sfc to be present in the dependency tree
Asked Answered
V

5

17

I'm working with the berry version of yarn with modules federation and vue3.
When I run these commands to create the base of the project:

mkdir vue-error
yarn set version stable
yarn plugin import workspace-tools
yarn init -pw
cd packages
npx create-mf-app # body
yarn
yarn workspace body add single-spa-vue
cd body
yarn start

I get the following error:

[webpack-cli] Failed to load '/Users/test/Development/trash/vue-error/packages/body/webpack.config.js' config
[webpack-cli] Error: @vitejs/plugin-vue requires vue (>=3.2.13) or @vue/compiler-sfc to be present in the dependency tree.
    at Object.<anonymous> (/Users/jcuzmar/Development/trash/vue-error/.yarn/__virtual__/vue-loader-virtual-8ff7836f4c/0/cache/vue-loader-npm-16.8.3-e05f7daca3-7c0566847b.zip/node_modules/vue-loader/dist/compiler.js:14:15)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.external_module_.Module._load (/Users/jcuzmar/Development/trash/vue-error/.pnp.cjs:17959:14)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/Users/jcuzmar/Development/trash/vue-error/.yarn/__virtual__/vue-loader-virtual-8ff7836f4c/0/cache/vue-loader-npm-16.8.3-e05f7daca3-7c0566847b.zip/node_modules/vue-loader/dist/index.js:8:20)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)

I tried adding:

packageExtensions:
  "@vitejs/plugin-vue@*":
    peerDependencies:
      'vue': '*'
      '@vue/compiler-sfc': '*'
      webpack: '*'

without success.

Vigor answered 16/12, 2021 at 22:48 Comment(0)
P
26

Upgrading vue to the latest available version solved the issue for me :)

If you’re using Yarn:

yarn add [email protected]

If you’re using NPM:

npm i [email protected]

Any version equal or above 3.2.13 should take care of it.

Prosser answered 25/12, 2021 at 21:52 Comment(5)
I'm using vue 2, upgrading to vue 3 would break everythingBijugate
I'm using vue 3.0.0 and using the above npm i command fix the problem with me. So the answer still standsWoodwind
For others, it may require pinning to 3.2.26, if you are on node 12.Indopacific
@Bijugate OP mentioned he's using Vue3.. If you're using vue2 and get this error, consider open a new SO questionBunting
@C.Bess That was my issue! Do you know why the error message says nothing about vue being incompatible with the node version?Nomination
P
3

Another point is to check your node version and if any of your VUE based plugins or dependencies require a specific node version. Fixed a VUE build for me.

Phlegmy answered 13/7, 2023 at 10:42 Comment(0)
C
2

Updating my node.js version helped resolve this issue.

I recommend installing node version manager to allow you to very easily swap between node versions.

Chiffon answered 30/12, 2023 at 17:53 Comment(0)
L
2

"@vue/compat": "^3.2.29", "vue": "^3.2.29", "@vue/compiler-sfc": "^3.2.29",

incase if you face this issue when you migrating. please

do

npm uninstall @vue/compiler-sfc

then

npm install @vue/[email protected]

it get fix.

Legend answered 11/1, 2024 at 11:16 Comment(0)
T
-2

If you’re using NPM:

npm i [email protected]

Toscanini answered 22/8, 2023 at 9:5 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.