SolvedDefinitelyTyped [@types/webpack] 'devServer' does not exist in type 'Configuration'

I'm using webpack-dev-server and before upgrading from v4.4.4 of @types/webpack, everything worked fine.
But now that I upgraded to v4.4.8, following warning is printed:

WARNING in [at-loader] ./webpack/development.ts:12:3 
    TS2322: Type '{ mode: "development"; devtool: "source-map"; devServer: { host: string; clientLogLevel: string; ...' is not assignable to type 'Configuration'.
  Object literal may only specify known properties, and 'devServer' does not exist in type 'Configuration'.

Config in question looks like this:

import * as webpack from "webpack";

import { commonConfig } from "./common";

const config: webpack.Configuration = {
  ...commonConfig,

  mode: "development",

  // Enable sourcemaps for debugging webpack's output.
  devtool: "source-map",
  devServer: {
    host: "0.0.0.0",
    clientLogLevel: "none",
    port: 3000
  }
};

export default config;

Could be a result from #26895.

13 Answers

✔️Accepted Answer

I had better results after explicitly merging the types:

import { Configuration as WebpackConfiguration } from "webpack";
import { Configuration as WebpackDevServerConfiguration } from "webpack-dev-server";

interface Configuration extends WebpackConfiguration {
  devServer?: WebpackDevServerConfiguration;
}

export const configuration: Configuration = {
  ...
  devServer: {
    historyApiFallback: true,
    hot: true,
    port: 3000
    ...
  }
  ...
}

Other Answers:

I think @types/webpack-dev-server contributes the devServer member now. Try installing it

Make sure you import both into your webpack config

import * as webpack from 'webpack';
import * as webpackDevServer from 'webpack-dev-server';

const config: webpack.Configuration = {}

If you import them both, then it works, but without the webpackDevServer import, it doesnt recognize the type

I got rid of the bug when I downgraded @types/webpack-dev-server from 3.11.3 to 3.11.1
It's not the best of solutions, but with time it will go away by itself :)

I think @types/webpack-dev-server contributes the devServer member now. Try installing it

That not works.

More Issues: