我尝试运行 webpack,但在终端中提示我安装 webpack-cli,我已经在我的项目中全局和本地安装了它......
One CLI for webpack must be installed. These are recommended choices, delivered as separate packages:
- webpack-cli (https://github.com/webpack/webpack-cli)
The original webpack full-featured CLI.
We will use "yarn" to install the CLI via "yarn add -D".
Do you want to install 'webpack-cli' (yes/no): yes
Installing 'webpack-cli' (running 'yarn add -D webpack-cli')...
再次尝试安装后,出现错误:
Error: Cannot find module 'webpack-cli'
Require stack:
- C:\Users\XXX\AppData\Local\Yarn\Data\global\node_modules\webpack\bin\webpack.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
at Function.Module._load (internal/modules/cjs/loader.js:725:27)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at C:\Users\XXX\AppData\Local\Yarn\Data\global\node_modules\webpack\bin\webpack.js:143:5
at processTicksAndRejections (internal/process/task_queues.js:93:5) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\\Users\\XXX\\AppData\\Local\\Yarn\\Data\\global\\node_modules\\webpack\\bin\\webpack.js'
]
}
这是我的 package.json:
{
"name": "ttttt",
"version": "1.0.0",
"description": "",
"main": "webpack.config.js",
"scripts": {
"dev": "webpack serve --mode development --env development",
"build": "webpack --config webpack.config.js",
"test": "echo \"Error: no test specified\" && exit 1",
"serve": "webpack serve --config webpack.config.js --progress --profile --content-base src/"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@babel/core": "^7.13.16",
"@webpack-cli/serve": "^1.3.1",
"babel-core": "^6.26.3",
"babel-loader": "^8.2.2",
"clean-webpack-plugin": "^4.0.0-alpha.0",
"copy-webpack-plugin": "^8.1.1",
"css-loader": "^5.2.4",
"file-loader": "^6.2.0",
"html-loader": "^2.1.2",
"html-webpack-plugin": "^5.3.1",
"mini-css-extract-plugin": "^1.5.0",
"node-sass": "^5.0.0",
"postcss-loader": "^5.2.0",
"sass-loader": "^11.0.1",
"style-loader": "^2.0.0",
"url-loader": "^4.1.1",
"webpack": "^5.35.0",
"webpack-cli": "^4.6.0",
"webpack-dev-server": "^3.11.2"
}
}