7

I'm having some issue with my project, when I run webpack-dev-server command, it show me not found, even I've installed twice webpack-dev-server!

Thanks!

  • 1
    are you using webpack4? – Ericgit Nov 25 '19 at 10:03
  • 1
    yeah, I'm using webpack4!, `npm install webpack webpack-cli webpack-dev-server` it successfully install, but later doesn't work! –  Nov 25 '19 at 10:05
  • 1
    have you updated your node and npm? – Ericgit Nov 25 '19 at 10:05
  • 2
    I think it would be helpful to copy/paste the exact error message, and the webpack config file, as well as the exact command you are running. – Mathieu Nov 25 '19 at 10:06
  • 1
    `node 10.15 && npm 5.8`, what the problem? –  Nov 25 '19 at 10:07
  • `webpack-dev-server: command not found ` –  Nov 25 '19 at 10:09
  • You might want to try solutions proposed here : https://stackoverflow.com/questions/31611527/webpack-webpack-dev-server-command-not-found – Mathieu Nov 25 '19 at 10:13
  • Does this answer your question? [Webpack - webpack-dev-server: command not found](https://stackoverflow.com/questions/31611527/webpack-webpack-dev-server-command-not-found) – Mathieu Nov 25 '19 at 10:13

2 Answers2

10

First of all, you have installed webpack, webpack-cli and webpack-dev-server the wrong way. You made them dependencies and not devDependencies. To change that, uninstall them:

npm uninstall webpack webpack-cli webpack-dev-server

and then install them properly:

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

Now, webpack-dev-server is in your node_modules folder. You can either run it from your terminal with

node node_modules/webpack-dev-server/bin/webpack-dev-server.js

or (as @nickbullock said), add a script in your package.json file and execute it from your terminal.

eyettea
  • 1,376
  • 2
  • 16
  • 35
1

webpack dev-server is not installed globally. please add it your scripts section in package.json

"scripts": {
  "dev-server": "webpack-dev-server"
}

and then run it from console: npm run dev-server

Also you can install it globally:
npm install -g webpack-dev-server
then you can run webpack-dev-server command on any project without local installation and adding to the scripts.

If you have global and local webpack-dev-server and using it with scripts, local version will be used.

nickbullock
  • 6,424
  • 9
  • 27