尝试运行 npm run dev 命令时遇到错误

我正在尝试按照非 javascript 教程进行操作,所以我正在尝试从节点脚本运行 webpack,但我遇到了这个奇怪的错误,我在网上搜索过但找不到解决方案


错误:C:\Users\Ahmad Usman\Desktop\9-forkify\webpack.config.js:2 const path = require("path"); ^


下面是代码(虽然它们在不同的文件中)


// 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",

};

这是我的命令行界面的 截图 commandline screenshot1

命令行截图2

谢谢


PIPIONE
浏览 133回答 1
1回答

宝慕林4294392

错误说:SyntaxError: identifier 'path' has already been declared因此,如果您删除重复代码,它应该可以工作://WEBPACK.CONFIG.JSconst path = require("path");const path = require("path"); <-- declared twicemodule.exports = {&nbsp; entry: "./src/js/index.js",&nbsp; output: {
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript