webpack-dev-server已使用与API架构不匹配的配置对象进行初始化

时间:2017-09-14 14:05:36

标签: webpack webpack-dev-server

到目前为止我所做的一切都是按照webpack上的指南进行的。

Windows 10。

最初我使用的是节点v6.11.1,但我现在已经升级到8.5.0,看看是否解决了这个问题;没有骰子。

我已经读过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? }
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! webpack-demo@1.0.0 start: `webpack-dev-server`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the webpack-demo@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! 2017-09-14T13_46_40_808Z-debug.log

我的webpack.config.js文件如下:

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

module.exports = {
    entry: {
        app: './src/index.js',
        print: './src/print.js'
    },
    output: {
        filename: '[name].bundle.js',
        path: path.resolve(__dirname, 'dist')
    },
    devServer: {
        contentBase: './dist',
    },
    plugins: [
        new CleanWebpackPlugin(['dist']),
        new HtmlWebpackPlugin({
            title: 'Output Management'
        })
    ],
    devtool: 'inline-source-map'
}

我的package.json文件

{
  "name": "webpack-demo",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "http-server",
    "watch": "webpack --progress --watch",
    "start": "webpack-dev-server --open",
    "build": "webpack"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "babel-cli": "^6.26.0",
    "babel-core": "^6.26.0",
    "babel-loader": "^7.1.2",
    "babel-preset-es2015": "^6.24.1",
    "clean-webpack-plugin": "^0.1.16",
    "css-loader": "^0.28.7",
    "file-loader": "^0.11.2",
    "html-webpack-plugin": "^2.30.1",
    "style-loader": "^0.18.2",
    "webpack": "^3.5.6",
    "webpack-dev-server": "^2.8.1"
  },
  "dependencies": {
    "lodash": "^4.17.4"
  }
}

1 个答案:

答案 0 :(得分:1)

这是直接的用户错误和疏忽。

在&#34之前;只需遵循指南"我正在弄乱别的东西,并使用start添加了http-server脚本。我不知道有多少次我看过package.json并错过了它,但它确实存在。平淡无奇。

它需要我关闭我的控制台,因为它在后台运行。关闭并重新打开控制台窗口并运行npm run startwebpack-dev-server工作正常。

随意敲响羞辱铃。