Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use globally installed webpack?

I want to use globally installed webpack, but executing the command webpack --mode development raises the message:

webpack not installed

Install webpack to start bundling: 
  $ npm install --save-dev webpack

despite that I have both webpack and webpack-cli installed. Am I right, that webpack says webpack not installed itself? Isn't it strange?

What to do to successfully build projects globally install webpack and loaders, but using local webpack.config.js?

like image 477
Gleb Kalachev Avatar asked Nov 06 '22 15:11

Gleb Kalachev


1 Answers

I was getting a similar error message, and it seems to be related to webpack not being found as a dependency of another package -- which by default won't include a globally installed package. As I understand it, the reason for an npm package to be installed globally is mainly so it can be accessed by the command line, and the general practice is to use local packages in all other situations, and even to install some packages both locally and globally.

Adding my global node_modules directory to my $NODE_PATH environment variable fixed this error message for me. However, this did not allow a globally installed babel-loader package to work with webpack, and I found it was much easier to just locally install the package I needed.

like image 116
squeevee Avatar answered Nov 17 '22 06:11

squeevee