reactjs - webpack-cli : Invalid options object. De

我想启动一个 redux 项目,下面提供了 package.json:

{
  "name": "redux-starter",
  "version": "1.0.0",
  "description": "Redux Starter Project",
  "main": "index.js",
  "scripts": {
    "start": "webpack-dev-server --config ./webpack.config.js",
    "test": "jest --watch"
  },
  "keywords": [],
  "author": "Mosh Hamedani",
  "license": "ISC",
  "devDependencies": {
    "@babel/core": "^7.8.7",
    "@babel/plugin-transform-runtime": "^7.8.3",
    "@babel/preset-env": "^7.8.7",
    "@types/jest": "^25.1.3",
    "axios-mock-adapter": "^1.17.0",
    "babel-jest": "^25.1.0",
    "jest": "^25.1.0",
    "webpack": "^4.46.0",
    "webpack-cli": "^4.9.2",
    "webpack-dev-server": "^4.7.4"
  },
  "dependencies": {
    "@reduxjs/toolkit": "^1.2.5",
    "axios": "^0.19.2",
    "immer": "^5.3.6",
    "immutable": "^4.0.0-rc.12",
    "lodash": "^4.17.15",
    "moment": "^2.24.0",
    "redux": "^4.0.5",
    "redux-devtools-extension": "^2.13.8",
    "reselect": "^4.0.0"
  }
}

webpack.config.js 在这里:

const path = require("path");

module.exports = {
  entry: "./src/index.js",
  output: {
    filename: "app.js",
    path: path.resolve(__dirname, "dist")
  },
  devServer: {
    contentBase: path.join(__dirname, "dist"),
    port: 9000
  },
  mode: "development",
  devtool: "source-map"
};

当我运行项目时,我收到错误,

$ npm start

> redux-starter@1.0.0 start
> webpack-dev-server --config ./webpack.config.js

[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? }

这是什么问题,我该如何解决?谢谢。

最佳答案

代替

devServer: {
    contentBase: path.join(__dirname, "dist"),
    port: 9000
},

使用:

devServer: {
    static: path.resolve(__dirname, 'dist')
    port: 9000
},

关于reactjs - webpack-cli : Invalid options object. Dev Server 已使用选项对象初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71524099/

相关文章:

python - 如何将字典的键值对收集到 Python 中的一个大字典中?

javascript - 找时间在一张图中写一个数字

visual-studio - Visual Studio 2022 无法添加服务引用且没有程序集引

typescript - 我可以根据参数更改返回类型吗

r - 取消列出嵌套列表的倒数第二个列表

amazon-web-services - 如何将事件从 EventBridge 发送到 Lambd

ASP.NET Core 6 - 从 swagger explorer 中隐藏最小的 api 端点

javascript - 使用javascript更新foreach循环中的数组对象

laravel - 如何通过单击进入 vs 代码中的一个类

python - 给定一个数字,找到到达它的序列