node.jslaravelnpmvitenpm-install

Could not resolve vite@"^4.0.0 || ^5.0.0" from @vitejs/plugin-vue@4.6.2 - How can install Vite ^6.2.4 from the root project?


I need help with this error. I could not do npm install, this error keeps popping up.

PS C:\path\to\project> npm install

code ERESOLVE
ERESOLVE unable to resolve dependency tree

While resolving: undefined@undefined
Found: vite@6.2.5
node_modules/vite
  dev vite@"^6.2.4" from the root project

Could not resolve dependency:
peer vite@"^4.0.0 || ^5.0.0" from @vitejs/plugin-vue@4.6.2
node_modules/@vitejs/plugin-vue
  dev @vitejs/plugin-vue@"^4.5.0" from the root project

Fix the upstream dependency conflict, or retry
this command with -- force or -- legacy-peer-deps
to accept an incorrect (and potentially broken) dependency resolution.

Do I need to install another version of Node.js/NPM? What should I do to fix this?


Solution

  • Problem

    By the way, your error is caused by the fact that @vitejs/plugin-vue v4.6.2 only supports Vite 4 or Vite 5 at most.

    Could not resolve dependency:
    peer vite@"^4.0.0 || ^5.0.0" from @vitejs/plugin-vue@4.6.2

    But your project requires at least v6.2.4.

    Found: vite@6.2.5
    vite@"^6.2.4" from the root project

    You will encounter the incompatibility message up until @vitejs/plugin-vue v5.2.0. You have two options.

    1.) If for some reason the @vitejs/plugin-vue version cannot be change

    To specifically use @vitejs/plugin-vue v4, you'll need Vite v5. (If a dependency you can't control requires @vitejs/plugin-vue v4, it might be worth suggesting an update in the appropriate repository. Otherwise, you'll be forced to use Vite v5 as well.)

    package.json

    {
      "devDependencies": {
        "@vitejs/plugin-vue": "^4.6.2",
        "vite": "^5.0.0",
      }
    }
    

    2.) Using up-to-date versions (recommended)

    However, the @vitejs/plugin-vue plugin was updated to support Vite v6 starting from v5.2.1; in that case, use at least @vitejs/plugin-vue v5.2.1. (Without debug information, it's unclear who is requesting the @vitejs/plugin-vue dependency. If you're able to control its version, increase it to at least v5.2.1 to ensure compatibility with Vite v6.)

    package.json (recommended)

    {
      "devDependencies": {
        "@vitejs/plugin-vue": "^5.2.1",
        "vite": "^6.0.0",
      }
    }