为什么我在 webpack 上得到无效的配置对象?

Why am I getting Invalid config object on webpack?

我正在通过 pluralsight 课程学习 webpack。我正在使用作者的 package.json 文件。

如果我 运行 只是 webpack 命令它 运行 没问题。

如果我 运行 webpack-dev-server,我得到以下信息:

Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
 - configuration.module has an unknown property 'preLoaders'. These properties are valid:
   object { exprContextCritical?, exprContextRecursive?, exprContextRegExp?, exprContextRequest?, loaders?, noParse?, rules?, unknownContextCritical?, unknownContextRecursive?, unknownContextRegExp?, unknownContextRequest?, unsafeCache?, wrappedContextCritical?, wrappedContextRecursive?, wrappedContextRegExp? }
   Options affecting the normal modules (`NormalModuleFactory`).
 - configuration.resolve.extensions[0] should not be empty.

这是我的webpack.config.js:

module.exports = {
    entry: ["./utils", "./app.js"],
    output: {
        filename: "bundle.js"
    },

    module: {
        preLoaders: [
            {
                test: /\.js$/,
                exclude: 'node_modules',
                loader: 'jshint-loader'
            }
        ],
        loaders: [
            {
                test: /\.es6$/,
                exclude: /node_modules/,
                loader: "babel-loader"
            }
        ]
    },

    resolve: {
        extensions: ['', '.js', '.es6']
    }
}

我的package.json:

  "devDependencies": {
    "babel-core": "^6.2.1",
    "babel-loader": "^6.2.0",
    "babel-preset-es2015": "^6.1.18",
    "jshint": "^2.8.0",
    "jshint-loader": "^0.8.3",
    "node-libs-browser": "^0.5.3",
    "webpack": "^1.12.9"
  }

您正在尝试 运行 webpack2 和 webpack1 的配置 - 您需要确保全局安装了 webpack1,因为您的课程是在 webpack1 - 而不是 webpack 2

如果你想坚持使用 Webpack 2,你可以更新你的 webpack.config.js

你不需要 Webpack 2 中的空扩展,所以你有

resolve: {
    extensions: ['', '.js', '.es6']
}

需要改成这样:

resolve: {
    extensions: ['.js', '.es6']
}