'webpack-dev-server' is not recognized as an internal or external command,
Asked Answered
M

8

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
Matted answered 14/8, 2018 at 20:26 Comment(0)
M
12

running

npm install -g webpack-dev-server

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

Matted answered 14/8, 2018 at 22:8 Comment(0)
B
31

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
Bayonne answered 15/10, 2019 at 12:54 Comment(2)
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 commandIntoxicate
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?Khalid
M
12

running

npm install -g webpack-dev-server

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

Matted answered 14/8, 2018 at 22:8 Comment(0)
M
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
Mcchesney answered 16/12, 2020 at 22:46 Comment(1)
In my case, I had already installed locally, but a re-install fixed the issue.Troat
B
2

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

Bentlee answered 14/8, 2018 at 20:41 Comment(1)
i ran "npm install -g webpack-dev-server" in cmd and it solved the problem.Matted
G
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

Germayne answered 2/5, 2021 at 12:18 Comment(0)
Z
0

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

Ziguard answered 25/3, 2021 at 10:50 Comment(0)
N
0

I solved this problem by typing command: npm update

Netherlands answered 13/7, 2021 at 19:13 Comment(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"Curb
S
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"

Sack answered 31/10, 2023 at 13:32 Comment(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.Lattimer

© 2022 - 2025 — McMap. All rights reserved.