我目前正在学习有关Udemy的课程,但我遇到了麻烦,运行脚本时遇到问题。当我运行命令npm run dev时,出现以下错误消息:
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] dev: `webpack`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the [email protected] dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\user\AppData\Roaming\npm-cache\_logs\2020-05-01T10_10_11_136Z-debug.log
怎么了?这是我的package.json代码:
{
"name": "forkify",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "webpack",
"build": "webpack --mode production",
"start": "webpack-dev-server --mode development --open"
},
"author": "Marv",
"license": "ISC",
"devDependencies": {
"babel-core": "^6.26.3",
"babel-loader": "^7.1.5",
"babel-preset-env": "^1.7.0",
"html-webpack-plugin": "^3.2.0",
"webpack": "^4.28.4",
"webpack-cli": "^3.2.1",
"webpack-dev-server": "^3.1.14"
},
"dependencies": {
"babel-polyfill": "^6.26.0"
}
}
这是webpack.config.js代码:
const path = require('path');
module.exports = {
entry: './src/js/index.js',
output: {
path: path.resolve(__dirname, 'dist/js'),
filename: 'bundle.js'
},
mode: 'development'
};
可能有什么问题?
更新:以某种方式我终于可以npm run dev
,但是它是在错误的目录中创建的。我该如何解决?enter image description here
我需要它出现在启动器下> dist> js
您的路径不好,将entry: './src/js/index.js'
替换为entry: './started/src/js/index.js'