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)
None of the above answers worked for me. If you are still getting this error, you can try this, this fixed my problem:
To:
To:
I fixed this solution by running
npm start
which was just a wrapper running 'webpack-dev-server' rather than runningwebpack-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
withnpm start
showed me the correct error message. Runningwebpack-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"
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:
Then, try rerunning 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 .
Try changing the webpack version from 1.x to 2.x in your package.json:
Eg:
This happens sometimes when you use pre-release version of
webpack-dev-server
with released version ofwebpack
or viceversa.To upgrade all packages (afer installing
webpack-cli
andwebpack-dev-server
), you canThat should fix the nonmatching version problem.