Angry Coder Angry Coder - 1 year ago 306
Node.js Question

webpack command not working

I am new to Node Js and Webpack. I tried to start a project with module-loaders.

First i installed nodeJs and npm and created a new directory

. I cd into this directory and did a
npm init
and then installed webpack via npm using the command below :

npm install -S webpack

The 1st command installed webpack locally into the project under the 'node-modules' directory and i can run my project by doing this :

nodejs node-modules/webpack/bin/webpack.js

the problem with this is that i have to place my
file inside of this directory which i want to place in my project root.

One solution to this problem was to install webpack globally on my machine which i did using the command below :

npm install -g webpack

This installed webpack and now i do have a webpack command, However this command does not seem to be working or doing anything at all. When i try to run this form mu project root directroy it does not do anything at all (See Screenshot)

enter image description here

Please tell me what i am doing wrong !!

Answer Source

webpack is not only in your node-modules/webpack/bin/ directory, it's also linked in node_modules/.bin.

You have the npm bin command to get the folder where npm will install executables.

You can use the scripts property of your package.json to use webpack from this directory which will be exported.

"scripts": {
  "scriptName": "webpack --config etc..."

For example:

"scripts": {
  "build": "webpack --config webpack.config.js"

You can then run it with:

npm run build

Or even with arguments:

npm run build -- <args>

This allow you to have you webpack.config.js in the root project of your folder without having webpack globally installed or having your webpack configuration in the node_modules folder.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download