英文:
Error: Cannot find module 'webpack-cli/bin/config-yargs'
问题
'Github' 要求我为安全原因将 'webpack-dev-server' 更新到版本 3.1.11 或更高版本。
然而,在更新后,'npm run dev' 将无法运行。
我不知道如何解决这个问题。
错误信息: 找不到模块 'webpack-cli/bin/config-yargs'。
'package.json' 的代码如下。
"dependencies": {
"@vue/cli-plugin-babel": "^3.5.1",
"config": "^3.0.1",
"vue": "^2.5.2",
"vue-router": "^3.0.1"
},
"devDependencies": {
"vue-jest": "^1.0.2",
"vue-loader": "^13.3.0",
"vue-style-loader": "^3.0.1",
"vue-template-compiler": "^2.5.2",
"webpack": "^3.12.0",
"webpack-bundle-analyzer": "^3.3.2",
"webpack-cli": "^3.3.10",
"webpack-dev-server": "^3.1.14",
"webpack-merge": "^4.1.0"
},
"engines": {
"node": ">= 6.0.0",
"npm": ">= 3.0.0"
},
"browserslist": [
"> 1%",
"last 2 versions",
"not ie <= 8"
]
(Note: The code block is provided for reference, but I won't translate it as requested.)
英文:
'Github' asked me to update 'webpack-dev-server' to version 3.1.11 or higher for security reasons.
However, 'npm run dev' will not run after the update.
I don't solve this problem
Error: Cannot find module 'webpack-cli/bin/config-yargs'
The code for 'package.json' is as follows.
"dependencies": {
"@vue/cli-plugin-babel": "^3.5.1",
"config": "^3.0.1",
"vue": "^2.5.2",
"vue-router": "^3.0.1"
},
"devDependencies": {
"vue-jest": "^1.0.2",
"vue-loader": "^13.3.0",
"vue-style-loader": "^3.0.1",
"vue-template-compiler": "^2.5.2",
"webpack": "^3.12.0",
"webpack-bundle-analyzer": "^3.3.2",
"webpack-cli": "^3.3.10",
"webpack-dev-server": "^3.1.14",
"webpack-merge": "^4.1.0"
},
"engines": {
"node": ">= 6.0.0",
"npm": ">= 3.0.0"
},
"browserslist": [
"> 1%",
"last 2 versions",
"not ie <= 8"
]
答案1
得分: 170
你可以尝试在package.json文件中的npm运行脚本中将webpack-dev-server
更改为webpack serve
。
英文:
You could try changing webpack-dev-server
to webpack serve
in your npm run script inside package.json
答案2
得分: 35
由于某种原因,Webpack团队将命令更改为 webpack serve
。请更改您的package.json文件:
"start": "webpack serve"
参考链接:https://github.com/webpack/webpack-dev-server/issues/2759
我正在使用的版本:
"webpack": "^5.10.0",
"webpack-cli": "^4.2.0",
"webpack-dev-server": "^3.11.0"
英文:
For some reason the webpack team changed the command to webpack serve
Change your package.json:
"start": "webpack serve"
Ref: https://github.com/webpack/webpack-dev-server/issues/2759
The version I am using:
"webpack": "^5.10.0",
"webpack-cli": "^4.2.0",
"webpack-dev-server": "^3.11.0"
答案3
得分: 21
只需执行以下两个步骤来修复它。
- 安装
npm i webpack-cli @webpack-cli/init
- 将以下内容添加到您的 package.json 文件中:
"scripts": { "start": "webpack-cli serve --mode development" },
完成!
英文:
To fix it just do 2 things.
- Install
npm i webpack-cli @webpack-cli/init
- Add this to your package.json:
"scripts": { "start": "webpack-cli serve --mode development" },
Done!
答案4
得分: 20
我同意你需要从webpack
3升级到4,但具体来说,以下是我必须执行的步骤,首先是因为webpack-cli
已经被拆分成一个单独的包:
$ npm install webpack webpack-cli --save-dev
如此解释:https://webpack.js.org/guides/getting-started/#basic-setup
英文:
I agree that you have to upgrade from webpack
3 to 4, but specifically these are the steps I had to do, first, because webpack-cli
has been split out into a separate package:
$ npm install webpack webpack-cli --save-dev
As explained here: https://webpack.js.org/guides/getting-started/#basic-setup
答案5
得分: 17
删除 package-lock.json 文件。在 package.json 中进行以下更改:
"webpack": "^4.32.2",
"webpack-cli": "^3.3.0",
"webpack-dev-server": "^3.11.0"
运行 npm install。
英文:
Delete package-lock.json file. Change following in package.json.
"webpack": "^4.32.2",
"webpack-cli": "^3.3.0",
"webpack-dev-server": "^3.11.0"
Run npm install
答案6
得分: 16
将package.json文件中的webpack-dev-server
更改为webpack serve
。
例如:
"scripts": { "start": "webpack serve --mode development --open" },
对我有效!;-)
英文:
Change webpack-dev-server
to webpack serve
in package.json file.
e.g.:
> "scripts": { "start": "webpack serve --mode development --open" },
It worked for me!
答案7
得分: 5
"scripts": {
"start": "webpack serve --mode development",
"build": "webpack --mode production"
},
运行:npm run start
或 npm start now
英文:
"scripts": {
"start": "webpack serve --mode development",
"build": "webpack --mode production"
},
Run: npm run start or npm start now
答案8
得分: 3
因为 webpack-cli 的版本问题。在某些版本中,没有 config-yargs.js 文件。所以 ^3.3.11
版本的 webpack-cli 对我有效。尝试以下命令:
npm i webpack-cli@^3.3.11
英文:
It is because of version of webpack-cli. In some versions, there is no config-yargs.js file. So ^3.3.11
version of webpack-cli worked for me.
Try it:
npm i webpack-cli@^3.3.11
答案9
得分: 1
webpack核心团队表示,从版本3+开始,兼容性将集中在webpack 4上,因此我认为您也需要将webpack 3更新到webpack 4。这份文档可能会帮助您实现这一目标:https://webpack.js.org/migrate/4
英文:
webpack core team says that form version 3+ the compatibility will foucs on webpack 4
so I think you need also to update webpack 3 to webpack 4
this doc may help you to achieve that
https://webpack.js.org/migrate/4
答案10
得分: 0
你需要检查最新版本的webpack、webpack-cli和webpack-dev-server,当你获取到这些信息后,编辑package.json以反映这些版本,然后运行yarn install --check-files。然后,你需要使用命令"npx webpack serve"启动webpack-dev-server。
英文:
You have to check to find out the latest versions of webpack, webpack-cli and webpack-dev-server and when you have that information edit package.json to reflect those versions and run yarn install --check-files Then you'll have to start the webpack-dev-server with the command "npx webpack serve"
答案11
得分: 0
尝试更改 package.json 文件中的一行:webpack-cli@4.10.0
然后在终端中运行以下命令:这对我有用。
npm install webpack-cli@4.10.0
npm install --save-dev webpack-cl
英文:
Try changing the package.json file line : webpack-cli@4.10.0
Then run below commands in terminal: It has worked for me.
npm install webpack-cli@4.10.0
npm install --save-dev webpack-cl
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论