0

I have nodejs installed on a MBP which runs OSX 10.9, I have installed as a package downloaded from the nodejs website. Then I have installed the MEAN stack following instructions on mean.io.

The commands are: sudo npm install -g mean-cli mean init yourNewApp

That works correctly

Now the real issue is when after my app is created I enter the dir using the terminal, and write gulp, and it thows me some errors that some mandatory modules are not found.

The modules are written in the package.json file that mean generated, and they are installed as global modules on ~/.npm

I browsed the folder and there are all the required packages folders, inside the folders there is a package.tgz file which has the code of the package and a package folder which holds a package.json file describing the package itself.

Now I don't understand why the packages are compressed and why if they are installed globaly can not be accessed from gulp on my project folder.

Thanks in advance.

asolenzal
  • 500
  • 7
  • 23
  • try `npm install` in your app directory – jsam Jun 23 '15 at 16:20
  • I have tried, and it works perfectly, but the question itself is because I can not use the globally installed modules, that's why they are installed globally – asolenzal Jun 23 '15 at 16:24
  • `~/.npm` is a cache directory, not a directory where (global) modules get installed. If Node can't find globally installed packages, see the answer [to this question](http://stackoverflow.com/questions/30974122/node-js-cant-require-modules-installed-globally-in-os-x/30974233). – robertklep Jun 23 '15 at 18:00
  • Thanks, you are right. Glad to know – asolenzal Jun 23 '15 at 18:07

1 Answers1

1

If you install some global module then you better don't put it into the package.json of your app because when you run your app that's the first place where is going to search and if it is there your app is going to look at node_modules folder and if it is not there your app will crash.

My advice is try to install your modules inside your app, npm install your_module --save because your app is gonna be portable and with a simple npm install you will be able to install all your needed packages.

But if you still wanna install global packages you maybe wanna follow this rules:

  1. If you’re installing something that you want to use in your program, using require('whatever'), then install it locally, at the root of your project.
  2. If you’re installing something that you want to use in your shell, on the command line or something, install it globally, so that its binaries end up in your PATH environment variable.

If you have the time to read the link then you will see that there are exceptions and how to handle them.

Gepser Hoil
  • 3,998
  • 4
  • 24
  • 34