Webpack-dev-server无效配置对象

时间:2017-09-19 16:20:55

标签: configuration webpack-dev-server

我正在尝试运行webpack-dev-server并且它给了我以下错误:

Invalid configuration object. webpack-dev-server has been initialised using 
a configuration object that does not match the API schema.
 - configuration has an unknown property 'error'. These properties are 
valid:
   object { hot?, hotOnly?, lazy?, bonjour?, host?, allowedHosts?, 
filename?, publicPath?, port?, socket?, watchOptions?, headers?, 
clientLogLevel?, overlay?, progress?, key?, cert?, ca?, pfx?, 
pfxPassphrase?, requestCert?, inline?, disableHostCheck?, public?, https?, 
contentBase?, watchContentBase?, open?, useLocalIp?, openPage?, features?, 
compress?, proxy?, historyApiFallback?, staticOptions?, setup?, stats?, 
reporter?, noInfo?, quiet?, serverSideRender?, index?, log?, warn? }

我不完全确定为什么这样做。 webpack运行得很好,但我不确定这是否重要。

这是我的package.json

{
  "name": "monettapage",
  "version": "1.0.0",
  "description": "Monetta Landing Page",
  "main": "webpack.config.js",
  "dependencies": {
    "babel-core": "^6.25.0",
    "babel-loader": "^7.1.1",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "css-loader": "^0.28.4",
    "file-loader": "^0.11.2",
    "html-webpack-plugin": "^2.29.0",
    "material-shadows": "^3.0.1",
    "material-ui": "^0.18.6",
    "material-ui-chip-input": "^0.15.3",
    "node-sass": "^4.5.3",
    "npm": "^5.4.2",
    "react": "^15.6.1",
    "react-dom": "^15.6.1",
    "react-router": "^4.1.1",
    "react-router-dom": "^4.1.1",
    "react-speech": "^0.3.2",
    "react-tap-event-plugin": "^2.0.1",
    "react-time": "^4.3.0",
    "react-voice-components": "^1.0.0",
    "sass-loader": "^6.0.6",
    "style-loader": "^0.18.2",
    "webpack": "^3.0.0",
    "webpack-dev-server": "^2.5.0"
},
  "scripts": {},
  "repository": {
    "type": "git",
    "url": "git+https://github.com/MonettaTech/monettapage.git"
  },
  "engines": {
    "node": "8.0.0",
    "npm": "5.0.3"
  },
  "author": "TDe",
  "license": "UNLICENSED",
  "bugs": {
    "url": "https://github.com/MonettaTech/monettapage/issues"
  },
  "homepage": "https://github.com/MonettaTech/monettapage#readme"
}

和我的webpack.config.js

const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');

const config = {
    entry: [
        './app/routes/routes.js'
    ],
    output: {
        path: path.resolve(__dirname,"docs"),
        filename: "index_bundle.js",
        publicPath: ""
    },
    module: {
        loaders: [
            {test: /\.jsx?$/, use: {loader:'babel-loader', options:{presets: ["react","es2015"], plugins: ["transform-es2015-arrow-functions"]}}, exclude: [/node_modules/,/dist/,/test/]},
            {test: /\.css$/, use:['style-loader','css-loader']},
            {test: /\.(scss|sass)$/, use: ['style-loader', 'css-loader','sass-loader']},
            {test: /\.(woff2?|jpe?g|png|gif|ico)$/, use: 'file-loader?name=./assets/images/[name].[ext]' },
            {test: /\.(eot|svg|ttf|woff|woff2)$/, use: 'file-loader?name=./assets/fonts/[name].[ext]' }
        ]
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: './app/index.html',
            filename: 'index.html',
            inject: 'body'
        })
    ],
    devServer: {
        port: 6969,
        historyApiFallback: true
    }
};

module.exports = config;

我还没有找到解决这个问题的答案。有趣的是,昨天它工作正常,今天它没有工作一次。

我已经运行npm install -g npm来更新npm,npm install -g webpack webpack-dev-servernpm update,问题仍然存在。

1 个答案:

答案 0 :(得分:0)

我最近遇到过类似的问题,你可以查看你的webpack-dev-server的版本。 V2.8.0 +可能是问题的原因。我将我的评级降级到2.7.1(固定),问题以某种方式解决了。