webpack-dev-server fails to start with a missing webpack/bin file
Error: Cannot find module 'webpack/bin/config-yargs'Short answer
This error appears when an old webpack-dev-server runs against a newer webpack that no longer has that file. Upgrade webpack-dev-server to v4 or later, install a matching webpack-cli, and start the server with webpack serve instead of the old binary call.
Fix it fast
1Find out which cause you have
List the three installed versions. The dev server and the CLI must both support your webpack version.
npm ls webpack webpack-cli webpack-dev-server2Match what you see, then jump to its fix
What does the error look like?
Error: Cannot find module 'webpack/bin/config-yargs'
Cause 1 of 2
webpack-dev-server is much older than webpack
1Check
The v4 release of the dev server needs webpack 4.37.0 at least and recommends webpack 5. Its migration guide lists the changes from older versions.
npm ls webpack-dev-server webpack2Fix
Upgrade the dev server, then update your config for the renamed options (contentBase became static, disableHostCheck became allowedHosts).
npm install --save-dev webpack-dev-server@latest3Verify
Start the server again.
npx webpack serveConfirmed by github.com
Cause 2 of 2
webpack-cli is missing or older than the dev server expects
1Check
The v4 dev server needs webpack-cli 4.7.0 or later. Since v4, webpack serve and the webpack-dev-server binary behave the same.
npm ls webpack-cli2Fix
Install a current webpack-cli and use webpack serve in your npm script.
npm install --save-dev webpack-cli@latest
// package.json
"scripts": { "start": "webpack serve --mode development" }3Verify
Run the script and open the printed address.
npm startConfirmed by github.com
How do I stop it coming back?
- Upgrade webpack, webpack-cli and webpack-dev-server together, not one at a time.
- Commit the lockfile so every machine installs the same versions.
- Read the dev server migration guide before a major upgrade.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Web apps
tsconfig rejects allowImportingTsExtensions
An error that allowImportingTsExtensions needs noEmit or emitDeclarationOnly
allowImportingTsExtensions lets files import each other with .ts or .tsx extensions, and TypeScript only allows it together with noEmit or emitDeclarationOnly.
2 causes, each with a fixWeb apps
Apollo Server rejects a request as a potential CSRF
HTTP 400 Bad Request from the GraphQL endpoint
Apollo Server's CSRF prevention is on by default.
3 causes, each with a fixWeb apps
React shows Attempted import error when importing a component or function
Attempted import error:
The build found the file but not the name you asked for.
2 causes, each with a fixWeb apps
AxiosError Network Error with code ERR_NETWORK in a React app
Network Error
ERR_NETWORK means the request produced no readable response.
4 causes, each with a fixWeb apps
Axios get works with a URL string but ignores the object passed as the second argument
The server log shows a GET with no query string
axios.get takes a URL and an optional config object.
3 causes, each with a fixWeb apps
Can't resolve '../axios' in a React project
Module not found: Error: Can't resolve '../axios'
A path that starts with ./ or ../ is a file path, not the axios package.
3 causes, each with a fix