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
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.
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.
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
running
npm install -g webpack-dev-server
in cmd as an administrator solved my problem. I hope it helps others.
Recent versions of Webpack & WDS need webpack-cli package, I recommend you to downloaded if your Webpack version is 4 or higher
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With