Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

webpack-dev-server fails to start with a missing webpack/bin file

ErrorError: 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.

  • Applies to webpack 5, webpack-dev-server 5, webpack-cli 5, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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-server
  2. 2Match what you see, then jump to its fix

    1. 1npm ls shows webpack-dev-server 2.x or 3.x next to webpack 4 or 5webpack-dev-server is much older than webpackFix
    2. 2npm ls shows no webpack-cli, or a version below 4.7webpack-cli is missing or older than the dev server expectsFix

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 webpack

2Fix

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@latest

3Verify

Start the server again.

npx webpack serve

Confirmed by github.com

Did this fix it?

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-cli

2Fix

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 start

Confirmed by github.com

Did this fix it?

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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.