Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

webpack: command not found after npm install webpack -g

Weird behaviour on my OSX Yosemite: from one day to another all my node modules installed by npm install -g were not found via the Terminal.

I'm not sure if this is due to my node v4.0.0 install the day before.

like image 343
imaginair Avatar asked Sep 13 '15 13:09

imaginair


2 Answers

Install it globally

npm i -g webpack

If you will work with webpack, install webpack-dev-server too

npm i -g webpack-dev-server

After I Install this two command I also found errors when run the

webpack

command so I figure out the problem by changing the version of webpack so I Install

npm install [email protected]

and every thing work fine for me.

I recommend you first learn a bit about npm and then webpack. You will struggle a lot. but finally you will find the right destination.

like image 94
Mohammed Elzanaty Avatar answered Sep 16 '22 23:09

Mohammed Elzanaty


Webpack is in your ./node_modules/.bin/ folder so instead of giving just webpack as the command try this.

./node_modules/.bin/webpack

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 folder of your project without having webpack globally installed or having your webpack configuration in the node_modules folder.

like image 23
Natesh bhat Avatar answered Sep 19 '22 23:09

Natesh bhat