简体   繁体   English

由于 node 和 webpack 版本冲突,无法安装依赖项

[英]can't install dependencies because of node and webpack version conflict

I am trying to install the dependencies with the exact version which are listed in json file, and I got errors below:我正在尝试使用 json 文件中列出的确切版本安装依赖项,但出现以下错误:

 npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree npm ERR! npm ERR! Found: webpack@4.46.0 npm ERR! node_modules/webpack npm ERR! webpack@"^4.35.3" from the root project npm ERR! npm ERR! Could not resolve dependency: npm ERR! peer webpack@"^5.1.0" from terser-webpack-plugin@5.3.1 npm ERR! node_modules/terser-webpack-plugin npm ERR! dev terser-webpack-plugin@"^5.1.1" from the root project npm ERR! npm ERR! Fix the upstream dependency conflict, or retry npm ERR! this command with --force, or --legacy-peer-deps npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

since the dependencies with the required version are not the latest one, I downgrade my node.js from latest version 16 to 14+, and install with npm i --leacy-peer-deps, but the error shows still the same, seems the version from node or webpack still not compatible to the dependencies(Found: webpack@4.46.0 npm ERR! node_modules/webpack npm ERR! webpack@"^4.35.3" from the root project).由于所需版本的依赖项不是最新的,我将 node.js 从最新版本 16 降级到 14+,并使用 npm i --leacy-peer-deps 安装,但错误显示仍然相同,似乎node 或 webpack 的版本仍然与依赖项不兼容(从根项目中找到:webpack@4.46.0 npm ERR!node_modules/webpack npm ERR!webpack@"^4.35.3")。

how can I solve this problem?我怎么解决这个问题?

here is the json list:这是json列表:

 { "name": "example-project", "version": "1.0.0", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "start": "node src/server/index.js", "build-prod": "webpack --config webpack.prod.js", "build-dev": "webpack-dev-server --config webpack.dev.js --open" }, "keywords": [], "author": "", "license": "ISC", "description": "", "dependencies": { "dotenv": "^8.2.0", "express": "^4.17.1", "jest-fetch-mock": "^3.0.3", "webpack": "^4.35.3", "webpack-cli": "^3.3.5" }, "devDependencies": { "@babel/core": "^7.13.15", "@babel/plugin-transform-modules-commonjs": "^7.13.8", "@babel/preset-env": "^7.13.15", "babel-loader": "^8.2.2", "body-parser": "^1.19.0", "clean-webpack-plugin": "^3.0.0", "cors": "^2.8.5", "css-loader": "^5.2.1", "html-webpack-plugin": "^3.2.0", "jest": "^26.6.3", "mini-css-extract-plugin": "^1.4.1", "node-fetch": "^2.6.1", "node-sass": "^5.0.0", "optimize-css-assets-webpack-plugin": "^5.0.4", "sass": "^1.32.8", "sass-loader": "^10.1.1", "style-loader": "^2.0.0", "terser-webpack-plugin": "^5.1.1", "webpack-dev-server": "^3.11.2", "workbox-webpack-plugin": "^6.1.5" } }

Try to delete package-lock.json and clear npm cache using 'npm cache clean -f' before npm i.尝试在 npm i 之前使用“npm cache clean -f”删除 package-lock.json 并清除 npm 缓存。

Caret (^) notation: It will update you to all future minor/patch versions, without incrementing the major version.插入符号 (^) 表示法:它将更新您到所有未来的次要/补丁版本,而不增加主要版本。 ^2.3.4 will use releases from 2.3.4 to <3.0.0 ^2.3.4 将使用从 2.3.4 到 <3.0.0 的版本

Tilde ( ~ ): It will update you to all future patch versions, without incrementing the minor version.波浪号(~):它将更新您到所有未来的补丁版本,而不增加次要版本。 ~1.2.3 will use releases from 1.2.3 to <1.3. ~1.2.3 将使用从 1.2.3 到 <1.3 的版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM