我正在尝试使用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.
由于与所需版本的依赖不是最新版本,我将我的node.js从最新版本16降为14+,并使用npm i-leacy对等-deps安装,但错误显示仍然相同,似乎版本来自节点或webpack仍然不兼容的依赖关系(发现: webpack@4.46.0 npm错误!节点模块/webpack npm错误!webpack@"^4.35.3“来自根项目)。
我该如何解决这个问题?
这是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"
}
}
发布于 2022-05-10 12:28:26
尝试删除包-lock.json,并在npm i.之前使用“npm缓存干净的-f”清除npm缓存。
Caret (^)表示法:它将更新到所有未来的小版本/补丁版本,而不增加主版本。^2.3.4将使用2.3.4至<3.0.0的版本
Tilde (~ ):它将更新到所有未来的补丁版本,而不增加次要版本。~1.2.3将使用从1.2.3到<1.3的版本。
https://stackoverflow.com/questions/72185993
复制相似问题