I was setting up a React project for a Chrome extension in which I needed more than one entry point and output in webpack, but I got an error when trying to configure more than one entry point in the webpack.config.js file. I have installed webpack 5.9, so according to the webpack documentation, this should work:
const path = require("path");
module.exports = {
mode: "development",
entry: {
editor: './src/editor/editor.js',
action: './src/action/action.js'
}, // if we make this object just the first string "./src/editor/editor.js" the command npm build works
output: {
filename: '[name]/[name].js', // Simple output file for testing
path: path.resolve(__dirname, "build"),
},
target: "web",
devServer: {
port: "3000",
static: ["./build"],
open: true,
hot: true,
liveReload: true,
},
resolve: {
extensions: [".js", ".jsx", ".json", ".ts"],
},
module: {
rules: [
{
test: /.(js|jsx)$/,
exclude: /node_modules/,
use: "babel-loader",
},
],
},
};
When I run the command npm run build (webpack .), the console throws this error:
“[webpack-cli] Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.
- configuration.entry[0] should be a non-empty string.
-> A module that is loaded upon startup. Only the last one is exported.”
what I am doing wrong?
my package.json file:
{
"name": "task_mananger_ext",
"version": "1.0.0",
"description": "",
"main": "./src/editor/editor.js",
"scripts": {
"test": "echo "Error: no test specified" && exit 1",
"start": "webpack-dev-server .",
"build": "webpack ."
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@babel/core": "^7.26.0",
"@babel/eslint-parser": "^7.25.9",
"@babel/plugin-transform-runtime": "^7.25.9",
"@babel/preset-env": "^7.26.0",
"@babel/preset-react": "^7.25.9",
"@babel/runtime": "^7.26.0",
"babel-eslint": "^10.1.0",
"babel-loader": "^9.2.1",
"webpack": "^5.96.1",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^5.1.0"
},
"dependencies": {
"react": "^18.3.1",
"react-dom": "^18.3.1"
}
}
i upload all in a repository at :https://github.com/FrancoDoce12/task_mananger_ext
Thanks for any help in advance!