Cannot Find Module 'Webpack/Bin/Config-Yargs'
Getting Error When Running Webpack-Dev-Server --Config Config/Webpack. Dev. Js --Progress --Profile --Watch --Content-Base Src/. Here Is the Error Log: Module...
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)
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.jsonscripts 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" }
Jan 2021
Using webpack 5, just replace the webpack-dev-server command with webpack serve
I've had a similar problem. I think it's related to webpack version. After changing webpack version the latest everything was fine...
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"
This is because of the changes in webpack-cli version.
- If the webpack-cli version is less than 4.x, You can use
webpack-dev-server - 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
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
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.
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"
}
I forgot to install webpack-cli. So I ran below command and issue got fixed.
npm i -D webpack-cli
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.
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
I solved this by creating a script command on package.json.
"dev": "webpack serve --config webpack.config.js --open",
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"
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 webpack-dev-server@1.15.0 -g
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"
}
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
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.
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.
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"
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"
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.
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.
Please use webpack serve for run webpack-dev-server
webpack serve --config config/webpack.dev.js --progress --profile --watch --content-base src/
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"
I tried the following lines and it was solved:
- As the issue is with webpack-dev-server so goto node-modules.
- find webpack-dev-server then goto dependencies
- check the dependency info of webpack and webpack-cli and their versions.
- 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
-> 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.
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.
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 :
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>
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, {