Error: Cannot find module 'webpack-cli/bin/config-yargs'

我只是一个虾纸丫 提交于 2020-12-04 19:12:12

问题


'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:


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




回答2:


You could try changing webpack-dev-server to webpack serve in your npm run script inside package.json




回答3:


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




回答4:


To fix it just do 2 things.

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

Done!




回答5:


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




回答6:


This process work for me

1 - Run your Command Invite/Terminal as Administrator

2 - Install the Vue CLI globally with the command :

npm install -g vue-cli

3 - Create your vue project

vue init webpack your_project_name_here

4 - Goto your project directory you

cd your_project_name_here

5 - If you have vulnerabilities execute :

npm audit fix

Now you can start the web server in development mode by using npm in the following way:

npm run dev

By default it will start the server on port 8080




回答7:


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



来源:https://stackoverflow.com/questions/59611597/error-cannot-find-module-webpack-cli-bin-config-yargs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!