Search code examples
reactjswebpack-2

Invalid configuration object in webpack.config.js


I get contiously this error

Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.

my webpack.config.js is as this

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')})
]
}

can somebody help me, I have tried many samples of webpack.config.js but they don't work. is it really so hard to work with react? I am new in react. I know how to code, but I can not build a project of my own


Solution

  • try the following snippet:

    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") })]
    };