webpack.config.js 中的配置对象无效

Invalid configuration object in webpack.config.js

我经常收到这个错误

无效的配置对象。 Webpack 已使用与 API 架构不匹配的配置对象进行初始化。

我的webpack.config.js是这样的

var path    = require('path');
var hwp     = require('html-webpack-plugin');

  module.exports = {
entry: path.join(__dirname, '/src/index.js'),
output: {
    filename: 'build.js',
    path: path.join(__dirname, '/dist')
},

module: {
    rules: [
        { test: /\.tsx?$/, loader: ['ts-loader'] },
        { test: /\.css$/, loader: "style-loader!css-loader" },
        {
            test: /\.scss$/, use: [{
                loader: "style-loader" // creates style nodes from JS 
strings
            }, {
                loader: "css-loader" // translates CSS into CommonJS
            }, {
                loader: "sass-loader" // compiles Sass to CSS
            }]
        },
        { test: /\.(otf|ttf|eot|svg|woff(2)?)(\?[a-z0-9=&.]+)?$/, 
 loader: 'file-loader?name=./Scripts/dist/[name].[ext]' }
    ]
},
plugins:[
    new hwp({template:path.join(__dirname, '/src/index.html')})
]
}

有人可以帮助我吗,我已经尝试了很多 webpack.config.js 的样本,但它们都不起作用。使用 React 真的那么难吗? 我是新手。我会写代码,但我不会自己建项目

尝试以下代码段:

var path = require("path");
var hwp = require("html-webpack-plugin");

module.exports = {
  entry: path.join(__dirname, "/src/index.js"),
  output: {
    filename: "build.js",
    path: path.join(__dirname, "/dist")
  },

  module: {
    rules: [
      { test: /\.tsx?$/, loader: ["ts-loader"] },
      { test: /\.css$/, loader: "style-loader!css-loader" },
      {
        test: /\.scss$/,
        use: [
          {
            loader: "style-loader" // creates style nodes from JS
          },
          {
            loader: "css-loader" // translates CSS into CommonJS
          },
          {
            loader: "sass-loader" // compiles Sass to CSS
          }
        ]
      },
      {
        test: /\.(otf|ttf|eot|svg|woff(2)?)(\?[a-z0-9=&.]+)?$/,
        loader: "file-loader?name=./Scripts/dist/[name].[ext]"
      }
    ]
  },
  plugins: [new hwp({ template: path.join(__dirname, "/src/index.html") })]
};