我正在尝试按照非 javascript 教程进行操作,所以我正在尝试从节点脚本运行 webpack,但我遇到了这个奇怪的错误,我在网上搜索过但找不到解决方案错误:C:\Users\Ahmad Usman\Desktop\9-forkify\webpack.config.js:2 const path = require("path"); ^下面是代码(虽然它们在不同的文件中)// INDEX.JS FIleimport num from "./test";console.log(`num: ${num}`);// TEST.JS FILEconsole.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.JSconst 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",};这是我的命令行界面的 截图 commandline screenshot1和命令行截图2谢谢
1 回答
宝慕林4294392
TA贡献2021条经验 获得超8个赞
错误说:
SyntaxError: identifier 'path' has already been declared
因此,如果您删除重复代码,它应该可以工作:
//WEBPACK.CONFIG.JS
const path = require("path");
const path = require("path"); <-- declared twice
module.exports = {
entry: "./src/js/index.js",
output: {
添加回答
举报
0/150
提交
取消