the shell cannot find webpack-dev-server
zsh: command not found: webpack-dev-serverShort 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.
Fix it fast
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-server2Match what you see, then jump to its fix
- 1
npm ls shows (empty) or missing for webpack-dev-server or webpack-cliThe packages are not installed in this projectFix - 2
The package is listed by npm ls, but the plain command is still not foundYou typed a local binary in the terminalFix - 3
The 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
- 1
What does the error look like?
zsh: command not found: webpack-dev-serverwebpack-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 | head2Fix
Install all three as dev dependencies.
npm install --save-dev webpack webpack-cli webpack-dev-server3Verify
The server starts and prints the address it runs on.
npx webpack serveConfirmed by webpack.js.org
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 webpack2Fix
Add a script and run that, or call the binary through npx.
// package.json
"scripts": {
"start": "webpack serve --open"
}
# terminal
npm start3Verify
npm start compiles and opens the browser.
npm startConfirmed by webpack.js.org
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-cli2Fix
Upgrade Node.js to a current LTS and reinstall the packages.
node -v
rm -rf node_modules package-lock.json
npm install3Verify
The server starts without engine warnings.
npx webpack serveConfirmed by webpack.js.org
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
Web apps
npm start fails because react-scripts is not found
react-scripts: command not found
npm runs scripts with node_modules/.bin on the PATH.
3 causes, each with a fixBack 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 fixBack end
ng fails with Cannot find module @angular/cli/bin/ng
Cannot find module '@angular/cli/bin/ng'
The ng command is the entry point to the Angular CLI package.
2 causes, each with a fixBack end
Angular app shows 'Cannot GET /' when served by a Node.js server
Cannot GET /dashboard
Cannot GET / is Express saying no route or file matches the request.
3 causes, each with a fixBack 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 fixBack end
Angular build says it cannot resolve '@angular/localize/init'
Can't resolve '@angular/localize/init' in '/usr/src/app/src'
The build imports @angular/localize, and that package is not in node_modules.
2 causes, each with a fix