错误: 无法找到模块 ‘webpack-cli/bin/config-yargs’

huangapple go评论108阅读模式
英文:

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.

  &quot;dependencies&quot;: {
    &quot;@vue/cli-plugin-babel&quot;: &quot;^3.5.1&quot;,
    &quot;config&quot;: &quot;^3.0.1&quot;,
    &quot;vue&quot;: &quot;^2.5.2&quot;,
    &quot;vue-router&quot;: &quot;^3.0.1&quot;
  },
  &quot;devDependencies&quot;: {
    &quot;vue-jest&quot;: &quot;^1.0.2&quot;,
    &quot;vue-loader&quot;: &quot;^13.3.0&quot;,
    &quot;vue-style-loader&quot;: &quot;^3.0.1&quot;,
    &quot;vue-template-compiler&quot;: &quot;^2.5.2&quot;,
    &quot;webpack&quot;: &quot;^3.12.0&quot;,
    &quot;webpack-bundle-analyzer&quot;: &quot;^3.3.2&quot;,
    &quot;webpack-cli&quot;: &quot;^3.3.10&quot;,
    &quot;webpack-dev-server&quot;: &quot;^3.1.14&quot;,
    &quot;webpack-merge&quot;: &quot;^4.1.0&quot;
  },
  &quot;engines&quot;: {
    &quot;node&quot;: &quot;&gt;= 6.0.0&quot;,
    &quot;npm&quot;: &quot;&gt;= 3.0.0&quot;
  },
  &quot;browserslist&quot;: [
    &quot;&gt; 1%&quot;,
    &quot;last 2 versions&quot;,
    &quot;not ie &lt;= 8&quot;
  ]

答案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:

&quot;start&quot;: &quot;webpack serve&quot;

Ref: https://github.com/webpack/webpack-dev-server/issues/2759

The version I am using:

&quot;webpack&quot;: &quot;^5.10.0&quot;,
&quot;webpack-cli&quot;: &quot;^4.2.0&quot;,
&quot;webpack-dev-server&quot;: &quot;^3.11.0&quot;

答案3

得分: 21

只需执行以下两个步骤来修复它。

  1. 安装
    npm i webpack-cli @webpack-cli/init
  2. 将以下内容添加到您的 package.json 文件中:
    "scripts": {
      "start": "webpack-cli serve --mode development"
    },
    

完成!

英文:

To fix it just do 2 things.

  1. Install
    npm i webpack-cli @webpack-cli/init
  2. Add this to your package.json:
    &quot;scripts&quot;: {
      &quot;start&quot;: &quot;webpack-cli serve --mode development&quot;
    },
    

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.

&quot;webpack&quot;: &quot;^4.32.2&quot;,
&quot;webpack-cli&quot;: &quot;^3.3.0&quot;,
&quot;webpack-dev-server&quot;: &quot;^3.11.0&quot;

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! 错误: 无法找到模块 ‘webpack-cli/bin/config-yargs’

答案7

得分: 5

"scripts": {
"start": "webpack serve --mode development",
"build": "webpack --mode production"
},

运行:npm run startnpm start now

英文:
&quot;scripts&quot;: {
    &quot;start&quot;: &quot;webpack serve --mode development&quot;,
    &quot;build&quot;: &quot;webpack --mode production&quot;
  },

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

然后在终端中运行以下命令:这对我有用。

  1. npm install webpack-cli@4.10.0
  2. 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.

  1. npm install webpack-cli@4.10.0
  2. npm install --save-dev webpack-cl

huangapple
  • 本文由 发表于 2020年1月6日 19:49:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/59611597.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定