reactjswebpack.config.js

Not able to run react project


I am new to reactjs. i am trying to write webpack.

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

module.exports = {
entry: './main.js',
output: {
  path: path.join(__dirname, '/bundle'),
  filename: 'index_bundle.js'
},
devServer: {
  inline: true,
  port: 3000
},
module: {
  rules: [
     {
        test: /\.jsx?$/,
        exclude: /node_modules/,
        loader: 'babel-loader',
        query: {
           presets: ['es2015', 'react']
        }
     },
     {
        test: /\.scss$/,
        use: [{
            loader: "style-loader"
        }, {
            loader: "css-loader"
        }, {
            loader: "sass-loader",
            options: {
                includePaths: ["absolute/path/a", "absolute/path/b"]
            }
        }]
     }
  ]
  },
  plugins:[
  new HtmlWebpackPlugin({
     template: './index.html'
  })
 ]
 }

Html Webpack Plugin: Error: Child compilation failed: Entry module not found: Error: Can't resolve 'F:\react-app\index.html' in 'F:\ react-app': Error: Can't resolve 'F:\react-app\index.html' in 'F:\react-app'


Solution

  • plugins:[
      new HtmlWebpackPlugin({
         hash:'true'
         template: './index.html'
      })
     ]
    

    Put hash to true and make sure you have the correct location of the template file.