使用yarn start启动项目时报错

package.json相关依赖如下

   "webpack": "^4.43.0",
    "webpack-cli": "^4.9.1",
    "webpack-dev-server": "^4.5.0"

在这里插入图片描述
报错信息如下:

[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? }
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

按提示,新版本的webpack配置文件webpack.config.json格式调整了,不支持contentBase

  devServer: {
    // open: true,
    contentBase: './',
    port: 3009
  },

修改成如下格式即可

{
  static: {
    directory: path.join(__dirname, './'),
  },
  compress: true,
  port: 9000,
}
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐