简体   繁体   English

尝试运行 npm 运行开发命令时遇到错误

[英]Running into error when trying to run npm run dev command

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我正在尝试遵循非 javascript 的教程,所以我试图从节点脚本运行 webpack 但我一直收到这个奇怪的错误,我已经在网上搜索但找不到解决方案

the error: C:\Users\Ahmad Usman\Desktop\9-forkify\webpack.config.js:2 const path = require("path");错误:C:\Users\Ahmad Usman\Desktop\9-forkify\webpack.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这是我的命令行界面命令行屏幕截图1

and commandline screenshot2命令行截图2

Thanks谢谢

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: {

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM