Mandrizzy's avatar

NPM install doesn't work think the reason is dependency in package-lock json file

I get the following error when I try to run npm install I know it has something to do with vite or the vite plugin but not sure how to fix it can anyone offer some advice.

npm error code ERESOLVE
npm error ERESOLVE could not resolve
npm error
npm error While resolving: @vitejs/[email protected]
npm error Found: [email protected]
npm error node_modules/vite
npm error   peer vite@"^5.0.0 || ^6.0.0" from [email protected]
npm error   node_modules/laravel-vite-plugin
npm error     dev laravel-vite-plugin@"^1.0" from the root project
npm error   dev vite@"^6.0" from the root project
npm error
npm error Could not resolve dependency:
npm error peer vite@"^4.0.0 || ^5.0.0" from @vitejs/[email protected]
npm error node_modules/@vitejs/plugin-vue
npm error   dev @vitejs/plugin-vue@"^4.5.0" from the root project
npm error
npm error Conflicting peer dependency: [email protected]
npm error node_modules/vite
npm error   peer vite@"^4.0.0 || ^5.0.0" from @vitejs/[email protected]
npm error   node_modules/@vitejs/plugin-vue
npm error     dev @vitejs/plugin-vue@"^4.5.0" from the root project
npm error
npm error Fix the upstream dependency conflict, or retry
npm error this command with --force or --legacy-peer-deps
npm error to accept an incorrect (and potentially broken) dependency resolution.
npm error
npm error

Here is a look at my package-lock json file which is triggering the error

{
            "devDependencies": {
                "@popperjs/core": "^2.11.6",
                "@vitejs/plugin-vue": "^4.5.0",
                "autoprefixer": "^10.4.20",
                "axios": "^1.7.4",
                "bootstrap": "^5.2.3",
                "concurrently": "^9.0.1",
                "laravel-vite-plugin": "^1.0",
                "postcss": "^8.4.47",
                "sass": "^1.56.1",
                "tailwindcss": "^3.4.13",
                "vite": "^6.0",
                "vue": "^3.2.37"
            }

Any ideas on what I should get rid of to make the npm install work without the force command

0 likes
1 reply
LaryAI's avatar
Level 58

The error you're encountering is due to a version conflict between vite and @vitejs/plugin-vue. The @vitejs/plugin-vue package requires a version of vite that is compatible with ^4.0.0 || ^5.0.0, but your project is using [email protected], which is not compatible with the plugin's requirements.

To resolve this issue, you have a couple of options:

  1. Downgrade Vite: If you don't specifically need Vite 6.x features, you can downgrade Vite to a version that is compatible with @vitejs/plugin-vue. You can do this by modifying your package.json to use a compatible version of Vite, such as ^5.0.0.

  2. Upgrade @vitejs/plugin-vue: Check if there is a newer version of @vitejs/plugin-vue that supports Vite 6.x. If such a version exists, you can upgrade the plugin.

Here's how you can downgrade Vite:

  1. Open your package.json file.
  2. Change the Vite version in devDependencies to a compatible version, such as ^5.0.0.
"devDependencies": {
    "@popperjs/core": "^2.11.6",
    "@vitejs/plugin-vue": "^4.5.0",
    "autoprefixer": "^10.4.20",
    "axios": "^1.7.4",
    "bootstrap": "^5.2.3",
    "concurrently": "^9.0.1",
    "laravel-vite-plugin": "^1.0",
    "postcss": "^8.4.47",
    "sass": "^1.56.1",
    "tailwindcss": "^3.4.13",
    "vite": "^5.0.0",  // Downgraded version
    "vue": "^3.2.37"
}
  1. Run npm install again to update your node_modules and package-lock.json.

If you prefer to upgrade @vitejs/plugin-vue, check the npm registry or the plugin's repository for a version that supports Vite 6.x, and update your package.json accordingly.

If neither option is feasible, you can temporarily use the --legacy-peer-deps flag with npm install to bypass the peer dependency conflict, but this is not recommended for long-term use as it may lead to other issues.

1 like

Please or to participate in this conversation.