javascript [email protected] 需要 webpack@^4.xx 的对等点,但没有安装

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/51293822/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 09:29:55  来源:igfitidea点击:

[email protected] requires a peer of webpack@^4.x.x but none is installed

javascriptreactjsnpmwebpackwebpack-dev-server

提问by Allan

Having a little trouble with React. Does anyone know how I can install the peer of webpack@^4.x.x?

React 有点麻烦。有谁知道我如何安装 webpack@^4.xx 的对等体?

This is the error I am recieving when I try to run

这是我尝试运行时收到的错误

webpack-dev-server

in cmd. It just returns

在 cmd 中。它只是返回

[email protected] requires a peer of webpack@^4.x.x but none is installed. You must install peer dependencies yourself.

回答by Tholle

webpack-dev-serverhas Webpack as a peer dependency, which means that you are responsible for installing that yourself.

webpack-dev-server将 Webpack 作为对等依赖项,这意味着您有责任自己安装它。

You could install the latest version of Webpack and add it to your devDependencieswith the following command:

您可以安装最新版本的 Webpack 并将其添加到您devDependencies的以下命令中:

npm i -D webpack@latest

By writing webpack-dev-serveryou are also trying to use the globally installed version of that package. You can use the locally installed one instead by adding it to a script in your package.json:

通过编写,webpack-dev-server您还尝试使用该软件包的全局安装版本。您可以使用本地安装的,而是将其添加到您的脚本中package.json

{
  "scripts" : {
    "start": "webpack-dev-server"
  }      
}

回答by Brian Li

If you need webpackupdated globally to the latest version, you can run:

如果需要webpack全局更新到最新版本,可以运行:

npm install -g webpack