Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

the shell cannot find webpack-dev-server

Errorzsh: command not found: webpack-dev-server

Short answer

The shell only knows commands that are on its PATH, and a project dev dependency is not. Install webpack, webpack-cli and webpack-dev-server in the project, then start it with npx webpack serve or from an npm script, where node_modules/.bin is available by name.

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

Fix it fast

  1. 1Find out which cause you have

    Check whether the project has the packages and the binary in node_modules.

    npm ls webpack webpack-cli webpack-dev-server
  2. 2Match what you see, then jump to its fix

    1. 1npm ls shows (empty) or missing for webpack-dev-server or webpack-cliThe packages are not installed in this projectFix
    2. 2The package is listed by npm ls, but the plain command is still not foundYou typed a local binary in the terminalFix
    3. 3The server fails right after start on an old Node.js (node -v shows below 18.12)Node.js is older than the dev server needsFix

What does the error look like?

  • zsh: command not found: webpack-dev-server
  • webpack-dev-server: command not found

Cause 1 of 3

The packages are not installed in this project

1Check

Run the command in the folder that holds package.json. A missing webpack-cli also stops webpack serve.

pwd
ls package.json node_modules/.bin | head

2Fix

Install all three as dev dependencies.

npm install --save-dev webpack webpack-cli webpack-dev-server

3Verify

The server starts and prints the address it runs on.

npx webpack serve

Confirmed by webpack.js.org

Did this fix it?

Cause 2 of 3

You typed a local binary in the terminal

1Check

A project binary lives in node_modules/.bin, which is not on your shell's PATH. npx and npm scripts look there for you.

ls node_modules/.bin | grep webpack

2Fix

Add a script and run that, or call the binary through npx.

// package.json
"scripts": {
  "start": "webpack serve --open"
}
# terminal
npm start

3Verify

npm start compiles and opens the browser.

npm start

Confirmed by webpack.js.org

Did this fix it?

Cause 3 of 3

Node.js is older than the dev server needs

1Check

webpack-dev-server 5 needs Node.js 18.12.0 or newer, webpack 5 and webpack-cli 4.7.0 or newer.

node -v
npm ls webpack webpack-cli

2Fix

Upgrade Node.js to a current LTS and reinstall the packages.

node -v
rm -rf node_modules package-lock.json
npm install

3Verify

The server starts without engine warnings.

npx webpack serve

Confirmed by webpack.js.org

Did this fix it?

How do I stop it coming back?

  • Keep webpack, webpack-cli and webpack-dev-server as dev dependencies of the project, not global installs.
  • Put the start command in an npm script so every teammate runs the same thing.
  • Commit the lockfile so installs match.

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

Back end

ng serve says it cannot determine the project or target

Cannot determine project for command.

The Angular CLI looked through angular.json for a project that defines the target you asked for (serve, build, test) and found none, or found several and could not pick one.

3 causes, each with a fix

Back end

ng serve cannot find the dev-server builder package

Could not find the implementation for builder @angular/build:dev-server

The builder named in angular.json (for example @angular-devkit/build-angular:dev-server) is looked up as an npm package starting from the workspace root.

3 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.