安装 Webpack 时 NPM 中出现 Webpack Peer Dependency 错误 [英] Webpack Peer Dependency Error in NPM When Webpack Is Installed
问题描述
在 npm 中运行 webpack-dev-server
时出现此错误:
I'm getting this error when running webpack-dev-server
in npm:
webpack-dev-middleware@3.7.2 requires a peer of webpack@^4.0.0 but none is installed. You must install peer dependencies yourself.
不过,我已经安装了 webpack.这是我的 package.json
.我错过了什么?
However, I already installed webpack. Here is my package.json
. What am I missing?
{
...
"scripts": {
"watch": "webpack-dev-server --progress --https"
},
...
"devDependencies": {
"webpack": "^5.4.0",
"webpack-cli": "^4.2.0",
"webpack-dev-server": "^3.11.0"
}
}
推荐答案
您已安装 webpack@5,但对等依赖警告要求使用 webpack@4.webpack-dev-server
关于与 webpack@5 不兼容的问题跟踪器.几天前,他们正在研究它.
You have webpack@5 installed but the peer dependency warning is asking for webpack@4. There is a bug filed in the webpack-dev-server
issue tracker about the incompatibility with webpack@5. As of a few days ago, they're working on it.
因此,一种选择是耐心观察该问题.当版本兼容的 webpack@5 发布时,升级到它.
So one option is to be patient and watch that issue. When a version compatible webpack@5 is released, upgrade to it.
另一种选择是将您当前的项目降级到 webpack@4.我不知道 webpack@4 和 webpack@5 之间的重大变化有多大,但这是一个可以尝试的选项.鉴于 webpack@5.0.0 仅在一个月前发布,这可能是一个不错的选择.webpack@4.x 的最新版本是 webpack@4.44.2,并且(在撰写本文时)只有 2 个月的历史.
Another option is to downgrade your current project to webpack@4. I don't know how big the breaking changes between webpack@4 and webpack@5 are, but it's an option to try. Given that webpack@5.0.0 was released only a month ago, this may be an OK option. The latest version of webpack@4.x is webpack@4.44.2 and (as of this writing) is only 2 months old.
这篇关于安装 Webpack 时 NPM 中出现 Webpack Peer Dependency 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!