0

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.

Sam
  • 26,817
  • 58
  • 206
  • 383

3 Answers3

2

Add the command as a npm script. In your package.json.

{
    "name": "app",
    "version": "0.0.1",
    "scripts": {
      "compile": "webpack --config webpack.config.js"
    }
}

Then run

npm run compile

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.

Liam
  • 27,717
  • 28
  • 128
  • 190
Nikhil Ranjan
  • 994
  • 12
  • 16
0

Yes it is obvious to get the error as you run some like:

webpack --config webpack.config.filename --progress

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

Avinash
  • 419
  • 2
  • 11
0

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.

./node_modules/.bin/webpack --config webpack.config.js"
Tom Van Rompaey
  • 3,556
  • 20
  • 22