22

I cloned this Webpack Starter package through github using gitbash following a tutorial on pluralsight. I am trying to access webpack through Visual Studio Code's integrated terminal but i get the following error. I am new to this so kindly help me on this.

I am running a command

 Raza Zaidi@RazaZaidi-PC MINGW64 ~/webpack-starter (master)
$ npm run dev

and then following error occurs

> yet-another-webpack-es6-starterkit@1.0.0 dev C:\Users\Raza Zaidi\webpack-starter
> webpack-dev-server --open --config webpack/webpack.config.dev.js

'webpack-dev-server' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! yet-another-webpack-es6-starterkit@1.0.0 dev: `webpack-dev-server --open --config webpack/webpack.config.dev.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the yet-another-webpack-es6-starterkit@1.0.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Raza Zaidi\AppData\Roaming\npm-cache\_logs\2018-08-14T20_16_29_017Z-debug.log
Raza Zaidi
  • 520
  • 1
  • 3
  • 17

7 Answers7

28

Webpack command should be present in location: node_modules\.bin\

In this case in package.json file we are referring to webpack-dev-server, but locally webpack-dev-server doesn't exist.

First run following command for global installation:

npm install -g webpack-dev-server

Second execute local installation command, which will create node_modules\.bin\webpack-dev-server:

npm install webpack-dev-server --save-dev
Paul Roub
  • 36,322
  • 27
  • 84
  • 93
S_K
  • 749
  • 1
  • 7
  • 10
  • 7
    Even though webpack-dev-server was in my package.json, I had to re-run `npm install webpack-dev-server --save-dev` to resolve my issue, didn't need to execute the first command – sometimes24 Jan 22 '20 at 17:10
  • 1
    Above solved my problem as well. Why do we manually have to install dependencies specified in package.json? Why are they not installed on npm install? – markussvensson Sep 12 '20 at 14:50
12

running

npm install -g webpack-dev-server

in cmd as an administrator solved my problem. I hope it helps others.

Raza Zaidi
  • 520
  • 1
  • 3
  • 17
5

For me, instead of installing webpack-dev-server globally, I simply uninstalled and reinstalled the local package:

npm uninstall webpack-dev-server
npm install webpack-dev-server
jmjohnson85
  • 347
  • 4
  • 9
2

Recent versions of Webpack & WDS need webpack-cli package, I recommend you to downloaded if your Webpack version is 4 or higher

1

first I've install webpack-dev-server in global

npm install -g webpack-dev-server

after installation I got this error..
Error: Cannot find module 'webpack'

this is version not matching problem, in my code I used these dependencies

"devDependencies": {
    "babel-core": "^6.26.3",
    "babel-loader": "^8.2.2",
    "babel-preset-es2015": "^6.24.1",
    "webpack": "2.2.0-rc.3",
    "webpack-cli": "^4.6.0",
    "webpack-dev-server": "2.1.0-beta.0",
    "webpack-validator": "^2.3.0"
  },

so change webpack-dev-server version in global

npm install -g webpack-dev-server@2.1.0-beta.0

in my case this was worked

tharsikan
  • 41
  • 5
0

Check your node version, in my case switching to last node version helped.

Jan Pi
  • 167
  • 2
  • 13
0

I solved this problem by typing command: npm update

  • This is the solution if you've forked a repository, and try to run in without installing its packages. I got this using yarn rather than npm, so the solution for me was just to type "yarn" – Jack Apr 19 '22 at 22:21