1

Unable to configure webpack with react

below is error :

Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema. - configuration.entry['main'] should not contain the item '—' twice. -> A non-empty array of non-empty strings

I have configured webpack and tried

below is webpack.config.js

 const path = require('path');
 const 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: /\.js$/,
      exclude: /node_modules/,
       loader: 'babel-loader'
    }]
  },
  plugins:[
    new HWP(
       {template: path.join(__dirname,'/src/index.html')}
   )
  ]
}

enter image description here

enter image description here

7
  • Just use create-react-app and save yourself from configuring webpack yourself. Commented Aug 30, 2019 at 10:30
  • I know create-react-app. I am trying to learn more on webpack. Commented Aug 30, 2019 at 10:33
  • Which line of code you have error ? Commented Aug 30, 2019 at 10:36
  • I think entry needs to be an array or object. try entry: { main: path.join(__dirname, '/src/index.js') }, Commented Aug 30, 2019 at 10:42
  • onfiguration.entry['main'] should not contain the item '—' twice. Commented Aug 30, 2019 at 10:42

3 Answers 3

2

I solve this adding "--live-reload false" to my start command.

"scripts": {

"ng": "ng",
"start": "ng serve --live-reload false",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test",
"build:single-spa:mf-test2": "ng build mf-test2 --prod",
"serve:single-spa:mf-test2": "ng s --project mf-test2 --disable-host-check --port NaN --live-reload false"   },
Sign up to request clarification or add additional context in comments.

Comments

0

i think this will work

 const path = require('path');
 const HWP = require('html-webpack-plugin');
 module.exports = {
   entry: ['./src/index.js'],
    output: {
    filename: 'build.js',
    path: path.join(__dirname, 'dist')},
module:{
   rules:[{
       test: /\.js$/,
      exclude: /node_modules/,
       loader: 'babel-loader'
    }]
  },
  plugins:[
    new HWP(
       {template: path.join(__dirname,'src/index.html')}
   )
  ]
}

1 Comment

same issue.--> invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema. - configuration.entry['main'] should not contain the item '—' twice.
0

changing scripts start command in package.json as below made it working,

"start": "webpack-dev-server --config webpack.config.js --port 3000",

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.