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

Aleksandar Terziev picture Aleksandar Terziev · Nov 2, 2016 · Viewed 70.4k times · Source

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) 

Answer

Serhii Matrunchyk picture Serhii Matrunchyk · Oct 5, 2020

If you're using webpack-cli 4, try to change from webpack-dev-server --open to webpack serve.

Example:

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

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" }