'I recently installed webpack and webpack-dev-server and getting this error on running it on localhost

I recently installed webpack and webpack-dev-server and getting this error on running it from terminal.

error: [webpack-cli] Invalid options object. Dev Server has been initialized using an options object that does not match the API schema. - options has an unknown property 'contentBase'. These properties are valid: object { allowedHosts?, bonjour?, client?, compress?, devMiddleware?, headers?, historyApiFallback?, host?, hot?, http2?, https?, ipc?, liveReload?, magicHtml?, onAfterSetupMiddleware?, onBeforeSetupMiddleware?, onListening?, open?, port?, proxy?, server?, setupExitSignals?, static?, watchFiles?, webSocketServer? }



Solution 1:[1]

Now webpack changed contentBase to static

To install webpack-dev-server

yarn add webpack-dev-server

or

npm install webpack-dev-server

then in webpack.config.js add this code

devServer: {
    static: {
        directory: path.join(__dirname, './public'),
    },
    // hot: true,
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1