Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 285
Raza Zaidi Avatar asked Aug 14 '18 20:08

Raza Zaidi


People also ask

Is not recognized webpack?

Use npx to solve the error "webpack is not recognized as an internal or external command, operable program or batch file", e.g. npx webpack or install the package locally by running npm install --save-dev webpack webpack-cli to use the command in your package. json file.

Can not find module webpack cli?

To solve the "Cannot find module 'webpack-cli'" error, make sure to install webpack-cli globally by running the npm i -g webpack-cli command and create a symbolic link from the globally-installed package to node_modules by running the npm link webpack-cli command.


3 Answers

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
like image 193
S_K Avatar answered Sep 20 '22 13:09

S_K


running

npm install -g webpack-dev-server

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

like image 27
Raza Zaidi Avatar answered Sep 18 '22 13:09

Raza Zaidi


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

like image 32
Benjamín Vázquez Avatar answered Sep 20 '22 13:09

Benjamín Vázquez