Webpack dev服务器TypeError:使用HotModuleReplacementPlugin时,回调函数不是函数

时间:2017-02-06 20:42:42

标签: webpack webpack-dev-server

我正在尝试使用webpack在react应用程序中实现热重新加载。这是我到目前为止设法制作的webpack的配置文件:

var ExtractTextPlugin = require('extract-text-webpack-plugin');
var combineLoaders = require('webpack-combine-loaders');
var webpack = require('webpack');

module.exports = {
  context: __dirname,
  entry: [
    'webpack-dev-server/client?http://localhost:3000', // WebpackDevServer host and port
    'webpack/hot/only-dev-server', // "only" prevents reload on syntax errors
    './app/StartUp.js'],
  output: {
    path: __dirname + "/../app/assets/webpack",
    filename: "[name].js"
  },
  resolve: {
    extensions: ['.js', '.jsx', '.css'],
  },
  module: {
    loaders: [
      { test: /\.jsx?$/,
        loaders: ["react-hot", "babel?presets[]=es2015,presets[]=stage-0,presets[]=react,plugins[]=transform-runtime"],
        exclude: /node_modules/
      },
      {
        test: /\.css$/,
        loader: ExtractTextPlugin.extract(
            'style-loader',
            combineLoaders([{
              loader: 'css-loader',
              query: {
                modules: true,
                localIdentName: '[name]__[local]___[hash:base64:5]'
              }
            }])
        )
      }
    ]
  },
  plugins: [
    new ExtractTextPlugin("main.css"),
    new webpack.HotModuleReplacementPlugin()
  ]
};

但是当我运行命令webpack-dev-server时,这给了我以下错误,我在过去几个小时内找不到解决方案:

webpack: Using compiler.parser is deprecated.
Use compiler.plugin("compilation", function(compilation, data) {
  data.normalModuleFactory.plugin("parser", function(parser, options) { parser.plugin(/* ... */); });
}); instead. It was called at HotModuleReplacementPlugin.apply (/Users/Rai/Documents/github/sarvahitey-core/client/node_modules/webpack/lib/HotModuleReplacementPlugin.js:162:18).
Project is running at http://localhost:8080/
webpack output is served from /
/Users/Rai/Documents/github/sarvahitey-core/client/node_modules/webpack/lib/NullFactory.js:9
    return callback();
           ^

TypeError: callback is not a function
    at NullFactory.create (/Users/Rai/Documents/github/sarvahitey-core/client/node_modules/webpack/lib/NullFactory.js:9:9)
    at iteratorFactory (/Users/Rai/.config/yarn/global/node_modules/webpack/lib/Compilation.js:229:12)
    at /Users/Rai/.config/yarn/global/node_modules/async/dist/async.js:3025:16
    at eachOfArrayLike (/Users/Rai/.config/yarn/global/node_modules/async/dist/async.js:941:9)
    at eachOf (/Users/Rai/.config/yarn/global/node_modules/async/dist/async.js:991:5)
    at Object.eachLimit (/Users/Rai/.config/yarn/global/node_modules/async/dist/async.js:3089:3)
    at Compilation.addModuleDependencies (/Users/Rai/.config/yarn/global/node_modules/webpack/lib/Compilation.js:210:9)
    at Compilation.processModuleDependencies (/Users/Rai/.config/yarn/global/node_modules/webpack/lib/Compilation.js:195:8)
    at _this.buildModule.err (/Users/Rai/.config/yarn/global/node_modules/webpack/lib/Compilation.js:335:13)
    at building.forEach.cb (/Users/Rai/.config/yarn/global/node_modules/webpack/lib/Compilation.js:140:27)

让我知道我哪里出错了。

0 个答案:

没有答案