How to fix: Error: Cannot find module 'webpack-cli/bin/config-yargs'?
How to fix: Error: Cannot find module 'webpack-cli/bin/config-yargs'?
我在网上查了很多文章并尝试应用建议,但没有任何效果。
我的配置如下:
package.json:
{
"name": "js_class",
"version": "1.0.0",
"description": "",
"main": "main.js",
"scripts": {
"build": "webpack --config webpack.config.js",
"webpack-dev-server": "webpack-dev-server",
"dev": "webpack-dev-server --mode=development",
"prod": "webpack --mode=production"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@babel/core": "^7.12.3",
"@babel/preset-env": "^7.12.1",
"babel-loader": "^8.1.0",
"html-webpack-plugin": "^4.5.0",
"path": "^0.12.7",
"webpack": "^5.3.2",
"webpack-cli": "^4.1.0",
"webpack-dev-server": "^3.11.0"
}
}
webpack.config.js:
const HtmlWebPackPlugin = require('html-webpack-plugin');
const path = require('path');
module.exports = {
entry: './index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js'
},
mode: 'development',
module: {
rules: [
{
test: /\.js$/,
exclude: /(node_modules)/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
}
]
},
devServer: {
contentBase: path.join(__dirname, 'dist'),
compress: true,
port: 9000
},
plugins: [
new HtmlWebPackPlugin()
]
};
错误:
internal/modules/cjs/loader.js:834
throw err;
^
Error: Cannot find module 'webpack-cli/bin/config-yargs'
Require stack:
- D:\Programiranje\Code\js\js_class\node_modules\webpack-dev-server\bin\webpack-dev-server.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:831:15)
at Function.Module._load (internal/modules/cjs/loader.js:687:27)
at Module.require (internal/modules/cjs/loader.js:903:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (D:\Programiranje\Code\js\js_class\node_modules\webpack-dev-server\bin\webpack-dev-server.js:65:1)
at Module._compile (internal/modules/cjs/loader.js:1015:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
at Module.load (internal/modules/cjs/loader.js:879:32)
at Function.Module._load (internal/modules/cjs/loader.js:724:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'D:\Programiranje\Code\js\js_class\node_modules\webpack-dev-server\bin\webpack-dev-server.js'
]
}
安装 webpack-cli 3.3.12 帮助解决问题。
我在网上查了很多文章并尝试应用建议,但没有任何效果。
我的配置如下:
package.json:
{
"name": "js_class",
"version": "1.0.0",
"description": "",
"main": "main.js",
"scripts": {
"build": "webpack --config webpack.config.js",
"webpack-dev-server": "webpack-dev-server",
"dev": "webpack-dev-server --mode=development",
"prod": "webpack --mode=production"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@babel/core": "^7.12.3",
"@babel/preset-env": "^7.12.1",
"babel-loader": "^8.1.0",
"html-webpack-plugin": "^4.5.0",
"path": "^0.12.7",
"webpack": "^5.3.2",
"webpack-cli": "^4.1.0",
"webpack-dev-server": "^3.11.0"
}
}
webpack.config.js:
const HtmlWebPackPlugin = require('html-webpack-plugin');
const path = require('path');
module.exports = {
entry: './index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js'
},
mode: 'development',
module: {
rules: [
{
test: /\.js$/,
exclude: /(node_modules)/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
}
]
},
devServer: {
contentBase: path.join(__dirname, 'dist'),
compress: true,
port: 9000
},
plugins: [
new HtmlWebPackPlugin()
]
};
错误:
internal/modules/cjs/loader.js:834
throw err;
^
Error: Cannot find module 'webpack-cli/bin/config-yargs'
Require stack:
- D:\Programiranje\Code\js\js_class\node_modules\webpack-dev-server\bin\webpack-dev-server.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:831:15)
at Function.Module._load (internal/modules/cjs/loader.js:687:27)
at Module.require (internal/modules/cjs/loader.js:903:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (D:\Programiranje\Code\js\js_class\node_modules\webpack-dev-server\bin\webpack-dev-server.js:65:1)
at Module._compile (internal/modules/cjs/loader.js:1015:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
at Module.load (internal/modules/cjs/loader.js:879:32)
at Function.Module._load (internal/modules/cjs/loader.js:724:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'D:\Programiranje\Code\js\js_class\node_modules\webpack-dev-server\bin\webpack-dev-server.js'
]
}
安装 webpack-cli 3.3.12 帮助解决问题。