Do I have to install webpack globally for me to issue webpack commands?
I installed webpack inside my project folder using npm install webpack --save-dev
and added it to dev dependencies. I'm inside my project folder and when I run a webpack command, I get the following error:
'webpack' is not recognized as an internal or external command, operable program or batch file.
BTW, I'm on Windows 10.
Yes it is obvious to get the error as you run some like:
this is similar to running a npm install command we need npm to be installed globally for the system to know what npm is so to run webpack in similar way you need to install webpack globally. Hope this helps
Add the command as a npm script. In your package.json.
Then run
npm scripts looks for executable created in ./node_modules/.bin folder. When the webpack is locally installed it creates a binary in the same folder.
Adding this command as a npm script like Nikhil Ranjan his answer is a good solution. Especially if you will be using this command several times.
Another way would be to directly call the executable inside the
node_modules
folder.