1

I run this command in my project folder

    npm install --global webpack webpack-dev-server

it return:

   /usr/lib

     ├── webpack@1.14.0
     └── webpack-dev-server@1.16.2

webpack and webpack-dev-server folders are under /usr/lib/node_modules, webpack command works, webpack-dev-server command return:

 webpack-dev-server: command not found

the configure json:

  "webpack": "^1.14.0",
  "webpack-dev-server": "^1.9.0" 

I also tried install in without -g, there is node_modules under the project folder, and .bin folder under node_modules. However webpack-dev-server is out of node_modules folder. I try move webpack-dev-server into .bin. it does not work either.

user1611237
  • 123
  • 1
  • 5
  • 14

2 Answers2

1

Try this:

npm install webpack-dev-server -g

From this answer: https://stackoverflow.com/a/31627310

EugenSunic
  • 13,162
  • 13
  • 64
  • 86
Surender Lohia
  • 349
  • 3
  • 12
0

installing packages globally is not good. Package.json does not define globally installed modules. When you run npm install command to setup a project, your project will not know about global modules.

You should install

npm i webpack-dev-server --save

then you need to add configuration into the webpack.config.js file. this is the related line for webpack-dev-server inside the file

 const path=require ("path")

{
    devServer: { contentBase: path.join(__dirname, "public") }

}

now you need to write this script on to package.json

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

this command will run your app

npm run dev-server
Yilmaz
  • 35,338
  • 10
  • 157
  • 202