16

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

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

webpack-dev-server

in cmd. It just returns

webpack-cli@3.0.8 requires a peer of webpack@^4.x.x but none is installed. You must install peer dependencies yourself.
Allan
  • 351
  • 1
  • 2
  • 11

2 Answers2

16

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

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

npm i -D webpack@latest

By writing webpack-dev-server you 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:

{
  "scripts" : {
    "start": "webpack-dev-server"
  }      
}
mikemaccana
  • 110,530
  • 99
  • 389
  • 494
Tholle
  • 108,070
  • 19
  • 198
  • 189
1

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

npm install -g webpack
Brian Li
  • 2,260
  • 1
  • 15
  • 18
  • 1
    What if that doesn't help? I installed webpack 4.42.0 globally, but webpack-cli doesn't see it... # npm list -g webpack /usr/local/lib └── webpack@4.42.0 # npm install -g webpack-cli npm WARN webpack-cli@3.3.11 requires a peer of webpack@4.x.x but none was installed. – Sinus the Tentacular Mar 03 '20 at 15:52
  • Come to think of it, what kind of semver is "4.x.x"? Shouldn't this be "^4.0.0" or something? – Sinus the Tentacular Mar 03 '20 at 15:56