1

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.

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"
  }
}
Zack
  • 49
  • 2
  • 6
  • 1
    `webpack@^4.0.0` means Webpack v4, you appear to have installed v5. Have a play with e.g. https://semver.npmjs.com/. – jonrsharpe Nov 07 '20 at 22:50

1 Answers1

2

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.

So one option is to be patient and watch that issue. When a version compatible webpack@5 is released, upgrade to it.

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.

Trott
  • 66,479
  • 23
  • 173
  • 212
  • Thanks! I assumed a later version would be compatible. Downgraded to 4.43.0 and it fixed the issue. – Zack Nov 08 '20 at 01:58