All jobs

Fix "Error: Cannot find module 'webpack-cli/bin/config-yargs'" When Starting webpack-dev-server

Yes. An agent works out which of webpack, webpack-cli and webpack-dev-server is the odd one out, aligns the three, and starts the dev server to prove it serves.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The error comes from a version mismatch between two packages, and neither is your code. webpack-dev-server 3 starts by loading a helper file from webpack-cli, webpack-cli/bin/config-yargs. webpack-cli 4 was rewritten and no longer ships that file; its bin directory holds only cli.js. So the pairing of dev server 3 with CLI 4 fails on the first require, and the stack names webpack-dev-server/bin/webpack-dev-server.js as the file that asked. The answer most people find is to change the start script to webpack serve. That works for some projects and not others, and the agent reads the dependency list before choosing.

jeffrafter/tinygif, an animated GIF encoder for the browser, is one where it does not. Its package.json declares "webpack": "^3.0.0", "webpack-cli": "^4.2.0" and "webpack-dev-server": "^3.11.0", and the start script is npx webpack-dev-server --open. No two of those three belong together. webpack-cli 4 expects webpack 4 or 5, and so does webpack-dev-server 3. With webpack 3 installed, the webpack command is webpack 3's built-in command line, which has no serve subcommand and takes the word as an entry name. A fresh npm install on a current npm does not even get that far: it stops with ERESOLVE on the peer dependency conflict.

The repository also contains the evidence of when it last worked. Next to package-lock.json, which matches the three ranges above, sits a yarn.lock that still resolves webpack-dev-server@^2.9.7 and webpack@^3.10.0, and the README tells contributors to run yarn start. webpack.config.js agrees with the older lockfile: it lists its loaders under module.loaders and passes Babel presets through query, a syntax webpack 3 accepts and webpack 4 rejects. The agent lays the two lockfiles side by side and concludes that the dev server and CLI were bumped without the bundler or the config.

It then proposes the two consistent states and builds the smaller one. Going back means webpack 3 with webpack-dev-server 2 and no webpack-cli, which needs no config change; that pair starts on a current Node and prints the address it serves on. Going forward means webpack 5, a matching CLI and dev server, webpack serve in the script, and a rewritten config: module.rules, options in place of query, a replacement for devServer.contentBase, and newer Babel and worker loaders. The agent implements the first, removes whichever lockfile the project no longer uses, starts the server without --open, and requests the bundle from it to confirm a response. It writes up the second as a plan with the files it would touch.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "Starting the dev server in this project fails with \"Error: Cannot find module 'webpack-cli/bin/config-yargs'\". Read package.json and every lockfile in the repository (package-lock.json, yarn.lock, pnpm-lock.yaml) and report the declared and locked versions of webpack, webpack-cli and webpack-dev-server, and whether the lockfiles agree with each other and with package.json. Install dependencies the way the README says, and if the install itself fails, record that error first and say what you did to get past it. Run the start script and save the error with its require stack. Explain which two packages are incompatible and what each of the three expects of the others. Read the webpack config and say which webpack major its syntax is written for. Then choose the smallest consistent set: either versions that match the config as written, or, if the project is already on webpack 4 or 5, a start script that uses webpack serve. Apply that option, keep one lockfile and delete the stale one, and say which you kept and why. Start the dev server without opening a browser, request the main bundle and the index page with curl, and include the status codes and the server's startup lines. Run the production build script as well. Do not rewrite the config for a newer webpack major in this change; describe that upgrade as a separate plan listing each config key and loader that would change. Open a pull request with the version table, the errors before, and the output after.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

A pull request that changes package.json, one lockfile and possibly a script line, and deletes the lockfile that no longer described the project. The description opens with a table of the three packages: declared range, version in each lockfile, version installed after the change. Below it are the original error, the install error if there was one, the dev server's startup output and the response codes for the bundle and the page, and the output of the build script.

A reviewer checks that the three versions are a set the packages themselves declare as compatible, by reading the peer dependency lines the description quotes, and that the remaining lockfile is the one their team's package manager uses. They read the upgrade plan as a proposal, not as work done. The agent can show that the server answers requests. It cannot judge by reading alone whether a page that draws to a canvas looks right, so if that matters, ask in a follow-up message for a screenshot of the running page, and the session resumes in the same sandbox with everything still installed.

Run it on every new contributor issue

This kind of breakage is found by whoever clones the project next. Their first npm start fails and they open an issue with the error pasted in. Give the Project an automation with a github trigger on issues.labeled and a label such as cannot-start, and a prompt that follows the README from a clean checkout, records the first command that fails and fixes the dependency set. The issue is added after the prompt as event text. The trigger fires only for an issue that an owner, member or collaborator of the repository opened, whoever adds the label, so a maintainer files the newcomer's report as an issue of their own and labels that one.

For a group of older front-end repositories, a schedule trigger with a monthly cron can run the same clean-checkout check ahead of any report. Most months it finds that install, start and build still work, and it opens nothing.

The use case this job follows, with its automation and trigger: Fix a bug from an alert.

Why run it on Rush?

The failure only exists on a clean install. A maintainer's machine has a node_modules directory from before the mismatch was introduced, so npm start keeps working there while it fails for everyone else. The agent's sandbox starts empty, so it sees what a new contributor sees, including the install error that comes before the one in the title. It can then install each candidate set of versions in turn and start the server on each, which is the actual test of whether three packages work together.

Old toolchains are also awkward to keep on a development machine. A bundler from several majors ago brings its own loaders, its own Babel and a tree of packages you would not otherwise install. In the sandbox they are installed, exercised and thrown away with the machine, and what you receive is the lockfile that worked, with the commands and output in the session to show how it was checked.

Frequently asked questions

Is changing the script to "webpack serve" the fix?

It is when webpack itself is version 4 or 5 and webpack-cli is 4 or newer: the CLI then starts the dev server and the missing file is never requested. It is not when the project is still on webpack 3, where the webpack command is a different program with no serve subcommand.

Can I downgrade webpack-cli to 3 instead?

Yes, if webpack is 4. webpack-cli 3 still has bin/config-yargs, and webpack-dev-server 3 works with it. The agent picks between that and webpack serve by which one changes fewer of your versions.

Why does npm install fail before I even reach this error?

Current npm enforces peer dependencies. If webpack-cli declares that it needs webpack 4 or 5 and the project asks for webpack 3, the install stops with ERESOLVE. Installing with --legacy-peer-deps gets past it and leads to the missing module at start. Both messages have the same cause.

My repository has both package-lock.json and yarn.lock. Does that matter?

It often explains the problem. Each package manager reads only its own lockfile, so two contributors can install different versions from the same commit. The agent compares them, keeps the one the README and CI use, and deletes the other.

More webpack-dev-server jobs

More jobs like this: Fix a bug from an alert

Keep reading