Cannot find module 'webpack/bin/config-yargs&#

2020-02-03 09:28发布

Getting error when running webpack-dev-server --config config/webpack.dev.js --progress --profile --watch --content-base src/. Here is the error log:

module.js:442
throw err;
^

Error: Cannot find module 'webpack/bin/config-yargs'
at Function.Module._resolveFilename (module.js:440:15)
at Function.Module._load (module.js:388:25)
at Module.require (module.js:468:17)
at require (internal/module.js:20:19)
at Module._compile (module.js:541:32)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3) 

14条回答
太酷不给撩
2楼-- · 2020-02-03 10:11

None of the above answers worked for me. If you are still getting this error, you can try this, this fixed my problem:

Open node_modules\webpack-dev-server\bin\webpack-dev-server.js

Change Line 84: require('webpack-cli/bin/config-yargs')(yargs);

To:

require('webpack-cli/bin/config/config-yargs')(yargs);

Change Line 92: const config = require('webpack-cli/bin/convert-argv')(yargs, argv, {

To:

const config = require('webpack-cli/bin/utils/convert-argv')(yargs, argv, {

查看更多
Animai°情兽
3楼-- · 2020-02-03 10:17

I fixed this solution by running npm start which was just a wrapper running 'webpack-dev-server' rather than running webpack-dev-server directly into the console. The problem was that I was passing options into a method I should not have been passing options into.

Running webpack-dev-server with npm start showed me the correct error message. Running webpack-dev-server directly only gave me "Error: Cannot find module 'webpack/bin/config-yargs' ". Weird.

I am on: "webpack": "^2.6.1", "webpack-dev-server": "^2.7.1"

查看更多
等我变得足够好
4楼-- · 2020-02-03 10:17

This is usually due to version mismatches between libraries (including webpack/yargs, in your case). This can happen a lot when you have left a project sitting for a while and some dependencies in your node_modules directory have become stale. A very simple solution, before fussing with different versions of everything, is to just move your node_modules directory to a temporary location and re-run npm install:

% mv node_modules nod_modules.REMOVED
% npm install

Then, try rerunning webpack.

查看更多
太酷不给撩
5楼-- · 2020-02-03 10:22

I had the same problem with webpack 4.

It is version compatible issue.

To fix the issue run following command to install webpack-cli in web pack 4 .

 yarn add webpack-cli -D
查看更多
再贱就再见
6楼-- · 2020-02-03 10:23

Try changing the webpack version from 1.x to 2.x in your package.json:

Eg:

 "devDependencies": {
    "webpack": "2.2.0-rc.3",
    "webpack-dev-server": "2.1.0-beta.0",
    "webpack-validator": "^2.3.0"
  }

This happens sometimes when you use pre-release version of webpack-dev-server with released version of webpack or viceversa.

查看更多
我想做一个坏孩纸
7楼-- · 2020-02-03 10:23

To upgrade all packages (afer installing webpack-cli and webpack-dev-server), you can

npm --depth=9999 upgrade

That should fix the nonmatching version problem.

查看更多
登录 后发表回答