I’m trying to follow a tutorial non javascript, so I’m trying to run webpack from node script but I’ve been getting this weird error, I’ve searched online but couldn’t find the solution
the error: C:UsersAhmad UsmanDesktop9-forkifywebpack.config.js:2 const path = require(“path”); ^
below is the code (they are in different files though)
// INDEX.JS FIle import num from "./test"; console.log(`num: ${num}`); // TEST.JS FILE console.log('imported module'); export default 23; // PACKAGE.JSON { "name": "forkify", "version": "1.0.0", "description": "forkify project", "main": "index.js", "scripts": { "dev": "webpack" }, "author": "Ahmad Usman", "license": "ISC", "devDependencies": { "webpack": "^4.44.1", "webpack-cli": "^3.3.12" } } //WEBPACK.CONFIG.JS const path = require("path"); const path = require("path"); module.exports = { entry: "./src/js/index.js", output: { path: path.resolve(__dirname, "dist/js"), filename: "bundle.js", }, mode: "development", };
and here is a screenshot of my command line interface commandline screenshot1
Thanks
Advertisement
Answer
The error says :
SyntaxError: identifier 'path' has already been declared
So if you remove duplicate code it should work:
//WEBPACK.CONFIG.JS const path = require("path"); const path = require("path"); <-- declared twice module.exports = { entry: "./src/js/index.js", output: {