【webpack】 Dev Server has been initialized using an options object that does not match 报错处理

问题:

npm run start启动本地服务的时候出现 Invalid options object. Dev Server has been initialized using an options object that does not match 报错

[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?, setupMiddlewares?, static?, watchFiles?, webSocketServer? }

在新版本的webpack-dev-server4.0中,contentBase属性已经被移除了,变成用static替代

contentBase是webpack-dev-server3.0的用法,如果不知道如何由v3升级到v4可以看这篇官方指南

解决方法:

devServer: {
    // contentBase: "./dist", v3用法
    static:'./dist', //v4用法
}

猜你喜欢

转载自blog.csdn.net/haidong55/article/details/128885935
今日推荐