23

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

> [email protected] 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! [email protected] dev: `webpack-dev-server --open --config webpack/webpack.config.dev.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] 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

8 Answers 8

29

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
2
  • 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 Jan 22, 2020 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? Sep 12, 2020 at 14:50
12

running

npm install -g webpack-dev-server

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

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
1
  • 1
    In my case, I had already installed locally, but a re-install fixed the issue. Dec 13, 2021 at 20:59
2

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

1
  • 1
    i ran "npm install -g webpack-dev-server" in cmd and it solved the problem.
    – Raza Zaidi
    Aug 14, 2018 at 22:09
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 [email protected]

in my case this was worked

0

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

0

I solved this problem by typing command: npm update

1
  • 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, 2022 at 22:21
0

if package.json file already exist with webpack, webpack-cli and dev server then simple use command npm install. Otherwise use commond npm install [email protected] or npm install --save-dev webpack@latest npm install --save-dev webpack-cli@latest npm install --save-dev webpack-dev-server@latest "webpack": "^4.30.0", "webpack-bundle-size-analyzer": "^3.0.0", "webpack-cli": "^3.3.1", "webpack-dev-server": "^3.3.1"

1
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Nov 3 at 13:59

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.