Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Webpack "Invalid configuration object" error

I am running into an error in my webpack config file that I am not sure how to solve. I set up the entry point to be a different location than index.html, and try to do npm run build, and I get this error:

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

  • configuration.entry should not contain the item ‘./mainPage/main.js’ twice.
    -> All modules are loaded upon startup. The last one is exported.

Here is the code for the webpack file:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

const path = require('path')

//we can make entries an array with [filePath, filePath2]

module.exports = {
    mode: "development",
    //devtool: '(none)',
    entry: "./mainPage/main.js" 
    ,
    output: {
        path: path.resolve(__dirname, "dist"),
        filename: "bundle.js",
        publicPath: __dirname + '/dist',
    },
    watch: true,

    module: {
      rules: [
        { test: /\.css$/, use: ['style-loader', 'css-loader' ]},
        { test: /\.ts$/, use: 'ts-loader' },
      ],
    } 
};

and here is my package.json file that I also modified:

{
  "name": "software-development",
  "version": "1.0.0",
  "description": "Food Forum Web App",
  "main": "./mainPage/main.js",
  "scripts": {
    "start": "webpack --config webpack.config.js",
    "test": "echo \"Error: no test specified\" && exit 1",
    "build": "webpack ./mainPage/main.js ./dist/bundle.js",
    "build:prod": "webpack "
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "file-loader": "^6.2.0",
    "html-loader": "^4.2.0",
    "html-webpack-plugin": "^5.5.1",
    "style-loader": "^3.3.2",
    "webpack": "^5.79.0",
    "webpack-cli": "^5.0.1"
  },
  "dependencies": {
    "firebase": "^9.19.1"
  }
}

any help with this would be amazing. Thank you!

>Solution :

The error you are encountering is due to an incorrect configuration in your package.json file. In the "scripts" section, you have specified the entry point ./mainPage/main.js in the "build" command, which causes the entry point to be specified twice when running the build command.

To fix the issue, update your "scripts" section in the package.json file to:

"scripts": {
  "start": "webpack --config webpack.config.js",
  "test": "echo \"Error: no test specified\" && exit 1",
  "build": "webpack --config webpack.config.js",
  "build:prod": "webpack "
},

This change ensures that the webpack configuration is used when running the build command, and you won’t encounter the duplicate entry point issue anymore.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading