Why are my Yeoman generators installing in the wrong place?
Asked Answered
S

4

36

I have a problem with Yeoman generators. They install just fine if I run "npm install [generator-name] -g". However when I try to run "yo [generator-name] yeoman can't seem to find the generator. Neither is it listed among my other generators if I just run "yo". I've tried a bunch of generators and the result is always the same.

After a bit of bit of investigation I found that the downloaded generator is placed in

/usr/local/lib/node_modules/

But my other generators are placed in

/usr/local/lib/share/npm/lib/node_modules/

Here is an image of how it looks on my machine https://i.sstatic.net/InQcZ.png, I'm running OSX in case that matters. Looks like something is wrong to me - but I cannot figure it out.

Not sure if this helps, but brew doctor and $NODE_PATH return nothing while $PATH returns:

-bash: 
/usr/local/share/npm/bin:
/Users/marcus/.rvm/gems/ruby-2.0.0-p247/bin:
/Users/marcus/.rvm/gems/ruby-2.0.0-p247@global/bin:
/Users/marcus/.rvm/rubies/ruby-2.0.0-p247/bin:
/Users/marcus/.rvm/bin:
/usr/bin:
/bin:
/usr/sbin:
/sbin:
/usr/local/bin:
/usr/local/git/bin: No such file or directory


UPDATE


I tried what Eddie Monge Jr suggested and now my angular generator works fine. However when I installed another generator (chrome-extension) yeoman insists that it's not installed/found.

When I run ls $(npm config get prefix)/lib/node_modules I get this:

bower                      generator-mocha
generator-angular          grunt-cli
generator-chrome-extension npm
generator-karma            yo

And npm list -g returns this (I cut out a lot of generic stuff)

/usr/local/lib
├─┬ [email protected]
├─┬ [email protected]
│ └─┬ [email protected]
├─┬ [email protected]
│ └─┬ [email protected]
├─┬ [email protected]
│ └─┬ [email protected]
├─┬ [email protected]
│ └─┬ [email protected]
├─┬ [email protected]
├─┬ [email protected]
└─┬ [email protected]

The strange part for me is if I run yo --help I get a strange list of generators

[?] What would you like to do?
  [ ] Run the Angular generator
  [ ] Run the Foundation generator
  [ ] Run the H5bp generator
  [X] Run the Mocha generator
  [ ] Run the Webapp generator
  [ ] Run the Karma generator
  [ ] Update your generators
  [ ] Install a generator
  [ ] Find some help
  [ ] Get me out of here!
Superconductivity answered 6/8, 2013 at 13:8 Comment(0)
H
49

I tried installing Yeoman on an Ubuntu precise32 vagrant vm. I ran into the same problem: Yeoman did not find the generators I installed, although there were no errors during the installation of these generators. Files were in place and permissions seemed alright.

The above solutions didn't work for me.

I ran

yo doctor

to see what was wrong, and as it turned out, the following was the problem:

[Yeoman Doctor] Uh oh, I found potential errors on your machine
---------------

[Error] NPM root value is not in your NODE_PATH
  [info]
    NODE_PATH = /usr/lib/nodejs:/usr/lib/node_modules:/usr/share/javascript
    NPM root  = /home/vagrant/npm/lib/node_modules

  [Fix] Append the NPM root value to your NODE_PATH variable
    Add this line to your .bashrc
      export NODE_PATH=$NODE_PATH:/home/vagrant/npm/lib/node_modules
    Or run this command
      echo "export NODE_PATH=$NODE_PATH:/home/vagrant/npm/lib/node_modules" >> ~/.bashrc && source ~/.bashrc

The fix suggested by the Yeoman Doctor worked as advertised.

Hammon answered 11/1, 2014 at 18:14 Comment(3)
How did you run [Yeoman Doctor]? Can't seem to figure it out.Superconductivity
I'll mark your reply as the answer since I'm quite sure that my issue was similar. I removed NPM and updated Node.JS to the latest version. I then installed NPM again using this SH script link. The script found and removed a couple of weird NPM paths and now it's up and running properly again. Cheers!Superconductivity
to run yeoman doctor, you need to locate doctor.js (with me, it was a path ending in .../yo/scripts/doctor.js and just run it with node. Also, what finally helped me to run yo was to start over with npm cache clean in between (after rm -rf /usr/local/lib/node_modules/yo, before reinstalling yo).Gertiegertrud
A
24

I hit this issue and I'm hoping it will help someone. I believe upgrading NPM caused this initial issue for me.

/usr/local/lib/node_modules

Was the location of a lot of my modules in the past. Since upgrading node at some point, the directory became

/usr/local/share/npm/lib/node_modules

When I would run new installations such as:

npm install -g grunt-cli

I since I run grunt from the command line it wouldn't 'find' it (that's because it wasn't in my new node_modules dir). I set up this up in my .bash_profile:

export PATH=$PATH:/usr/local/share/npm/bin

Now I am pointing to the new node_modules directory So all the new npm modules I install find the right location: /usr/local/share/npm/lib/node_modules

But not yo

I ran a which yo and my path was

/usr/local/bin/yo

This binary was pointing to the OLD node_modules installation @

/usr/local/lib/node_modules

My solution was to do this

rm /usr/local/bin/yo
npm remove -g yo

The old reference to yo is gone for keeps, now I can do

npm install -g yo

This will add it to the new node_modules location

/usr/local/share/npm/lib/node_modules

and now the new 'yo' references the proper node_modules installation base

source ~/.bash_profile

then we can see yo is referenced from the proper spot

which yo
/usr/local/share/npm/bin/yo

all future generators will be placed in the proper node_modules directory and yo will be able to find them without a problem!

Ajmer answered 12/2, 2014 at 23:22 Comment(2)
Sounds pretty much like the error I had. I did try npm remove -g yo a couple of times without success however. What I didn't do was to run rm /usr/local/bin/yo, I'm not sure if that would have solved made any difference though. But thanks!Superconductivity
This made it for me! I also added a symlink to the bash_profile to make yo work. The following line: PATH=${PATH}:~/.node/bin and don't forget to restart the prompt for the change to take action.Varela
M
7

I uninstalled yeoman entirely, then re-installed it

npm remove -g yo
npm install -g yo

This fixed my problem with missing angular generators.

Melano answered 18/11, 2013 at 3:2 Comment(0)
H
1

Sounds like your npm may be out of whack. Check where things are installed: npm config get prefix Is that where you expected the packages to install? Is that where they are currently installed?

To list whats in there:

ls $(npm config get prefix)/lib/node_modules

That will list out the globally installed npm packages.

npm list -g

Will list the currently installed things. Make sure yo and the generators are listed at the top level.

To remove the yo stuff and start over:

npm remove -g yo generator-* yeoman-generator
npm install -g yo generator-angular

That should fix things.

Hierogram answered 21/8, 2013 at 15:26 Comment(3)
Thanks for your reply! I don't have access to my work computer right now but I'll give it a shot tomorrow.Superconductivity
Hmm my angular generator now works, I've tried both the chrome-extension and backbone generator without luck however - Yeoman can't seem to find it. I've updated my question above.Superconductivity
yep, since I removed the yo generator stuff I can npm update && npm -g update without warnings again. I wanted to checkout the yeoman workflow.Ammonal

© 2022 - 2024 — McMap. All rights reserved.