1
votes

I run this command in my project folder

    npm install --global webpack webpack-dev-server

it return:

   /usr/lib

     ├── [email protected]
     └── [email protected]

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.

2
I found an alternative way to make it work: run npm and webpack from the host machine.user1611237

2 Answers

0
votes

Try this:

npm install webpack-dev-server -g

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

0
votes

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