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

WebpackWebpack Dev-Server

Webpack Problem Overview


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) 

Webpack Solutions


Solution 1 - Webpack

If you're using webpack-cli 4 or webpack 5, change webpack-dev-server to webpack serve.

Example:

"serve": "webpack serve --config config/webpack.dev.js --progress"

You might want also check this comment on GitHub:

> NPM package.json scripts are a convenient and useful means to run > locally installed binaries without having to be concerned about their > full paths. Simply define a script as such: > > For webpack-cli 3.x: > > "scripts": { "start:dev": "webpack-dev-server" } > > For webpack-cli 4.x: > > "scripts": { "start:dev": "webpack serve" } >

Solution 2 - Webpack

Jan 2021

Using webpack 5, just replace the webpack-dev-server command with webpack serve

Solution 3 - Webpack

I've had a similar problem. I think it's related to webpack version. After changing webpack version the latest everything was fine...

Solution 4 - Webpack

Update: March 21

Try to update your webpack dependencies with the following command

npm install --save-dev webpack webpack-cli webpack-dev-server

if it does not work then use as following

I am having these dependencies but I faced the same issue

"webpack": "^5.6.0",
"webpack-cli": "^4.2.0",
"webpack-dev-server": "^3.11.0"

And I found a solution that adding a new script or in your Start Script in package.json worked for me. So you can try this way as well.

"dev": "webpack serve --mode development --env development"

Solution 5 - Webpack

Solution

package.json

"scripts": {
    "startdev": "webpack serve --mode development --env development --hot --port 3000"
    ...
    ...
  },
"devDependencies": {
...
    "webpack": "^5.10.1",
    "webpack-cli": "^4.2.0"
 },

Console

$ npm run startdev

Solution 6 - Webpack

This is because of the changes in webpack-cli version.

  1. If the webpack-cli version is less than 4.x, You can use webpack-dev-server
  2. If the webpack-cli version is 4.x or higher, you can use webpack serve

For webpack-cli 3.x and below

    "scripts": {
      "dev-server": "webpack-dev-server"
    }

For webpack-cli 4.x and above

    "scripts": {
      "dev-server": "webpack serve"
    }
    "scripts": {
      "dev-server": "webpack serve "
    }

Source: webpack dev-server

Solution 7 - Webpack

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.

Solution 8 - Webpack

The issue is with newer webpack-cli version. If webpack-cli <= 3.x webpack-dev-server package work fine. For webpack-cli >= 4.x, use npx webpack serve command to run local server.

For webpack-cli 3.x:
"scripts": {
  "start:dev": "webpack-dev-server --mode=development"
}

For webpack-cli 4.x:
"scripts": {
  "start:dev": "webpack serve --mode=development"
}

Solution 9 - Webpack

I forgot to install webpack-cli. So I ran below command and issue got fixed.

npm i -D webpack-cli

Solution 10 - Webpack

Update your Webpack version (and webpack CLI):

npm install --save-dev webpack webpack-cli webpack-dev-server webpack-merge

If you don't use one of those mentioned above, feel free to omit.

Solution 11 - Webpack

I also go this error when I had only installed webpack locally and hadn't installed it globally yet.

I had webpack-dev-server installed globally though and it had a dependency on a global install of webpack. To be fair npm did complain while installing webpack-dev-server:

> UNMET PEER DEPENDENCY webpack@^2.2.0

Solution 12 - Webpack

I solved this by creating a script command on package.json.

"dev": "webpack serve --config webpack.config.js --open",

Solution 13 - Webpack

In my case the solution was just use previous versions -

"webpack": "^4.44.1",
"webpack-cli": "^3.3.12",
"webpack-dev-server": "^3.11.0"

Solution 14 - Webpack

The general situation is due to Webpack and webpack-dev-server version is not compatible. Like I also have this problem, my computer's webpack is 1.15.0, but webpack-dev-server is 2.x above version. So I uninstall webpack-dev-server: npm uninstall webpack-dev-server -g Then install the 1.15.0 version of webpack-dev-server, you can solve this problem by npm install [email protected] -g

Solution 15 - Webpack

Try changing webpack version to 3.0 and web-dev-server to 2.7.1

Eg:

"devDependencies": {
    "webpack": "^3.0.0",
    "webpack-cli": "2.0.13",
    "webpack-config-utils": "2.0.0",
    "webpack-dev-server": "^2.7.1",
    "webpack-validator": "2.2.7"
}

Solution 16 - Webpack

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

Solution 17 - Webpack

I've had a similar problem. I think it's related to webpack version.

UPDATE JULY 2021

People who have versions of "webpack-cli": "^4 or above", & "webpack": "^5 or above",.

You can give a try updating your webpack version by this command

npm install --save-dev webpack webpack-cli webpack-dev-server

Now go to you package.json, under scrpits add this line

"dev": "webpack serve --mode development --env development"

This totally worked for me.

Solution 18 - Webpack

Deprecate the webpack-cli version by using the command :

npm install -D webpack-cli@3

The new version is in the Beta phase and likely to fix this bug.

Solution 19 - Webpack

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"

Solution 20 - Webpack

I had got the following dependencies installed (without specifying any particular version)

 "webpack-cli": "^4.5.0",
 "webpack-dev-server": "^3.11.2"

This error appears during the yarn start with the following entry in package.json specific to the scripts.start attr.

 "scripts": {
    "start": "webpack-dev-server --open",
    "build": "webpack"
  }

So, it turns out that webpack-dev-server --open is looking for webpack-cli version 3.3. I got rid of this error by installing the specific version of webpack-cli The working package.json looks like this:

  "webpack-cli": "3.3",
  "webpack-dev-server": "^3.11.2"

But, if you don't want to downgrade the webpack-cli version, update the "start": "webpack-dev-server --open" to "start": "webpack serve --open"

Solution 21 - Webpack

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.

Solution 22 - Webpack

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.

Solution 23 - Webpack

Please use webpack serve for run webpack-dev-server

webpack serve --config config/webpack.dev.js --progress --profile --watch --content-base src/

Solution 24 - Webpack

It's webpack versioning problem You need to update your webpack using this command

npm install --save-dev webpack webpack-cli webpack-dev-server

Now in package.json file use

"dev": "webpack serve --config webpack.config.js --open"

Solution 25 - Webpack

I tried the following lines and it was solved:

  1. As the issue is with webpack-dev-server so goto node-modules.
  2. find webpack-dev-server then goto dependencies
  3. check the dependency info of webpack and webpack-cli and their versions.
  4. Reinstall those names with the exact same versions.

Then try re-running the dev-server.

In my case: "dev-server": "webpack-dev-server --open"

console: npm run dev-server

Solution 26 - Webpack

-> So, first do you exclude the node_modules folder.
->after verificad if in the archive package.json the dependencies : "webpack", "webpack-cli" and "webpack-dev-server" they are in "dependencies":{}.
-> The end, Open the terminal execute the command : yarn. the install all depends again that was excluded.

Solution 27 - Webpack

Changing the command from "serve": "webpack-dev-server" to "serve":"webpack serve" solved this issue. I've tried this solution with webpack dev server v3.11.0 and v3.11.2; both worked fine.

Solution 28 - Webpack

use webpack serve instead of webpack-dev-server in your package.json under scripts. it perfectly work for me. I had the same error and this fixed it.

my devDependencies:

"webpack": "^5.22.0",
"webpack-cli": "^4.5.0",
"webpack-dev-server": "^3.11.2"

original post : https://stackoverflow.com/a/64304022/11739552

Solution 29 - Webpack

I just solved it.

The problem was on path on index.html.

from:

<script src="./dist/myBundle.js"></script>

to:

<script src="myBundle.js"></script>

Solution 30 - Webpack

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, {

Solution 31 - Webpack

downgrade webpack-cli

npm install -D webpack-cli@3

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAleksandar TerzievView Question on Stackoverflow
Solution 1 - WebpackSerhii MatrunchykView Answer on Stackoverflow
Solution 2 - WebpackZach SmithView Answer on Stackoverflow
Solution 3 - WebpackNikola SpalevicView Answer on Stackoverflow
Solution 4 - WebpackShivam ModiView Answer on Stackoverflow
Solution 5 - WebpackipegasusView Answer on Stackoverflow
Solution 6 - WebpackAnand RajaView Answer on Stackoverflow
Solution 7 - WebpackSridhar SgView Answer on Stackoverflow
Solution 8 - WebpackCoderOO7View Answer on Stackoverflow
Solution 9 - WebpackKarthikView Answer on Stackoverflow
Solution 10 - WebpackRaz BuchnikView Answer on Stackoverflow
Solution 11 - WebpackLukePView Answer on Stackoverflow
Solution 12 - WebpackVinceView Answer on Stackoverflow
Solution 13 - WebpackOlegView Answer on Stackoverflow
Solution 14 - WebpackmspriyakkView Answer on Stackoverflow
Solution 15 - WebpackSHRIDHARView Answer on Stackoverflow
Solution 16 - WebpackManuja JayawardanaView Answer on Stackoverflow
Solution 17 - WebpackMahijendraView Answer on Stackoverflow
Solution 18 - WebpackDKTView Answer on Stackoverflow
Solution 19 - WebpackAustin KimView Answer on Stackoverflow
Solution 20 - WebpackBinita BharatiView Answer on Stackoverflow
Solution 21 - WebpackRob BaileyView Answer on Stackoverflow
Solution 22 - Webpackserv-incView Answer on Stackoverflow
Solution 23 - WebpackFarshad jahanmaneshView Answer on Stackoverflow
Solution 24 - WebpackMD SHAYONView Answer on Stackoverflow
Solution 25 - WebpackRidwanur RahmanView Answer on Stackoverflow
Solution 26 - WebpackDanrleyView Answer on Stackoverflow
Solution 27 - WebpackKaisar sarwarView Answer on Stackoverflow
Solution 28 - WebpackHeshanHHView Answer on Stackoverflow
Solution 29 - WebpackVinceView Answer on Stackoverflow
Solution 30 - WebpackstamhaneyView Answer on Stackoverflow
Solution 31 - WebpackArvind kumarView Answer on Stackoverflow