gpt4 book ai didi

javascript - webpack和webpack-dev-server安装报错

转载 作者:行者123 更新时间:2023-12-05 02:03:50 25 4
gpt4 key购买 nike

我正在尝试安装 Webpack 和 Babel 以在没有 CRA 的情况下使用 React。

在安装 webpack-dev-server 的过程中,我遇到了一些依赖问题

PS C:\Users\Lebedev\Desktop\projects\frontend-graduation-project> npm install --save-dev webpack-dev-server
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! Found: webpack@5.4.0
npm ERR! node_modules/webpack
npm ERR! peer webpack@">=2" from babel-loader@8.2.1
npm ERR! node_modules/babel-loader
npm ERR! dev babel-loader@"^8.2.1" from the root project
npm ERR! peer webpack@"^4.27.0 || ^5.0.0" from css-loader@5.0.1
npm ERR! node_modules/css-loader
npm ERR! dev css-loader@"^5.0.1" from the root project
npm ERR! 6 more (html-webpack-plugin, style-loader, ...)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer webpack@"^4.0.0" from webpack-dev-middleware@3.7.2
npm ERR! node_modules/webpack-dev-server/node_modules/webpack-dev-middleware
npm ERR! webpack-dev-middleware@"^3.7.2" from webpack-dev-server@3.11.0
npm ERR! node_modules/webpack-dev-server
npm ERR! dev webpack-dev-server@"*" 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.
npm ERR!
npm ERR! See C:\Users\Lebedev\AppData\Local\npm-cache\eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Lebedev\AppData\Local\npm-cache\_logs\2020-11-15T12_42_34_324Z-debug.log
PS C:\Users\Lebedev\Desktop\projects\frontend-graduation-project>

我的 package.json 文件:

"dependencies": {
"react": "^17.0.1",
"react-dom": "^17.0.1"
},
"devDependencies": {
"@babel/core": "^7.12.3",
"@babel/preset-env": "^7.12.1",
"@babel/preset-react": "^7.12.5",
"babel-loader": "^8.2.1",
"css-loader": "^5.0.1",
"html-webpack-plugin": "^4.5.0",
"style-loader": "^2.0.0",
"webpack": "^5.4.0",
"webpack-cli": "^4.2.0"
}

我已经做了但仍然没有帮助:

  1. 尝试删除 node_modules 文件夹
  2. 尝试删除 package-lock.json 文件
  3. 通过运行以下命令重新安装 npm 依赖项:npm install

如何解决这个问题?

谢谢你的建议

最佳答案

我在 Github 问题页面上找到了答案:https://github.com/npm/cli/issues/2119

我的 npm 版本是 7.0.8。作为问题中的 mvyunko 提及,我只需输入以下内容:

npm install npm@latest -g
npm install webpack-dev-server --save-dev

所有命令后,我的npm版本已经改为6.14.8,安装报错也没有了。

关于javascript - webpack和webpack-dev-server安装报错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64844600/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com