8

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!

8
  • 1
    are you using webpack4? Commented Nov 25, 2019 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! Commented Nov 25, 2019 at 10:05
  • 1
    have you updated your node and npm? Commented Nov 25, 2019 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. Commented Nov 25, 2019 at 10:06
  • 1
    node 10.15 && npm 5.8, what the problem? Commented Nov 25, 2019 at 10:07

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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.

1 Comment

now it's working, thanks! but before we could do like that!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.