Why are my Yeoman generators installing in the wrong place? - npm

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 http://i.imgur.com/DxWTYHb.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
├─┬ bower#1.2.3
├─┬ generator-angular#0.4.0
│ └─┬ yeoman-generator#0.13.3
├─┬ generator-chrome-extension#0.2.3
│ └─┬ yeoman-generator#0.12.3
├─┬ generator-karma#0.5.0
│ └─┬ yeoman-generator#0.13.3
├─┬ generator-mocha#0.1.1
│ └─┬ yeoman-generator#0.10.5
├─┬ grunt-cli#0.1.9
├─┬ npm#1.3.5
└─┬ yo#1.0.0
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!

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.

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!

I uninstalled yeoman entirely, then re-installed it
npm remove -g yo
npm install -g yo
This fixed my problem with missing angular generators.

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.

Related

NPM global package install not working properly

Tearing my hair out over this.
I used to have a npm package called 'eleventy' installed globaly and working on my laptop. Today I find this: fish: Unknown command 'eleventy'
Tried this npm install -g eleventy and got this
+ eleventy#0.2.0
updated 1 package in 0.289s
Things tried from other posted questions:
npm get prefix outputs /usr/local
ls /usr/local/lib/node_modules/ outputs eleventy npm
but not eleventy found in /usr/local/bin
echo $PATH = /usr/local/php5/bin/ /usr/local/bin /usr/local/lib /usr/bin /bin /usr/sbin /sbin
Tried reinstalling npm and nodejs as well but no luck so far. Any help appreciated.
Okay, looks like I'm an idiot. I was installing the wrong package with a similar name.
I needed to use
npm install -g #11ty/eleventy

npm: using 'npm uninstall' vs. just removing the folder

I wanted to try grunt-babel, so I opened up a terminal in my Home folder and did npm install --save-dev grunt-babel babel-preset-es2015 according to the plugin's instructions.
I was doing this too hastily, and realized I should probably have done this in my new project folder where I am dabbling with ES6 code. I had not even done npm init in that folder nor in the Home folder from where I executed the install command.
When I do npm uninstall grunt-babel, the preset files are removed but 91 folders of different dependencies remain in the node_modules folder.
Can I simply remove the folder instead of running npm uninstall 91 times?
This guy asked a similar question but none of the answers address his subquestion of just removing the folder: how to uninstall npm modules in node js?
npm uninstall <name> removes the module from node_modules, but not package.json.
npm uninstall <name> --save to also delete the dependency from package.json.
npm rm <package_name> removes the packages when uninstall not working
npm prune <name> (see docs) for extraneous packages and packages that are not listed on the parent package's dependencies list.
If you don't want to uninstall one by one run
rm -rf node_modules && npm cache clean && npm install
It's a good way for being sure the packages you uninstall are no more in the packages json.
Now in 2021 npm uninstall <name> will also removed it from package.json
UPDATED answer (2020):
These are all aliases to uninstall:
remove, rm, r, un, unlink
And today there is no need for --save flag since it is the default. The same goes for install BTW.
Use npm list as a tool to understand your changes. I usually use the time to make a capture file like:
npm list >1307
do some change
npm list >1309
so then:
cat 13??
or an editor lets me see what npm thinks it did.
For uninstall, only packages on the root all size of 'whole package' get removed. Other then that, the command is politely ignored...
For example:
├── safe-stable-stringify#1.1.0
├── semver#6.3.0
├─┬ tableify#1.1.0
│ └─┬ optimist#0.6.1
│ ├── minimist#0.0.8 deduped
│ └── wordwrap#0.0.3
safe-stable-stringify is a removal candidate, but wordwrap is not. Think about it, this is entirely reasonable !
npm uninstall pkgtoyank -save
updates packages.json by removing it from there as well.
npm is very well designed to say the least. I usually hugely avoid directly poking under it in ./node_modules I will copy things out from there to look at them, but why yank on a leash of a BIG CAT and get bit. it works; use it as its intended....

How to change npm path

All my npm packages work, but my npm package list shows empty. I am sure this is issue with a path but not sure how to fix it.
Which gulp gives me >
[~] ruby-2.2.3 $ which gulp
/usr/local/bin/gulp
Which npm gives me >
[~] ruby-2.2.3 $ which npm
/usr/local/bin/npm
npm list gives me >
[~] ruby-2.2.3 $ npm list
/Users/kimmo
└── (empty)
It looks like you are confusing packages that are installed globally with those locally. The paths for gulp and npm look like the global install locations. Packages you install locally will be found under a node_modules folder in the root of your project.
You can confirm this by comparing the results from:
npm ls -g --depth=0
npm ls --depth=0
The first command will show the globally installed packages. The second will show the local packages.
At the top of the resulting output, each shows the directory where the global or local install is located.
Finally, the --depth=0 flag only shows the packages that were required and not the dependencies of those packages (and those packages, etc). I find that most of the time, that's all I care about. If you agree, you can easily make this a default with npm config set depth 0 or by editing your .npmrc file in your home directory.
So! My guess is that you installed gulp with the -g flag but you haven't installed anything locally (with no flag, so to speak). That's why there's a difference between what which is showing and npm ls is showing.

gulp-plumber module cannot be found?

I'm fairly new to Gulp and I can't overcome one issue.
I need to install my dependencies globally (not locally), so I've done npm -g install & also tried to install them all separately with -g flag.
Anyway, SASS works, Coffee works, everything works, but when I run "gulp" i get:
module.js:338
throw err;
^
Error: Cannot find module 'gulp-plumber'
Checking if it's installed:
npm list -g gulp-plumber
/usr/local/lib
└── gulp-plumber#1.0.1
Looks a-okay.
Checking SASS the same way:
npm list -g gulp-sass
/usr/local/lib
└── gulp-sass#2.1.0
If they're both installed why my gulp "can't see" plumber alone? How do I fix that?
Please try below command it should work.
npm set registry http://registry.npmjs.org/

Yeoman can't recognize a generator that was installed globally

I ran sudo npm install -g generator-flask and it was saved. I was able to confirm by running npm list-g.
I then run yo flask. Thinking that this was going to work, I instead get an error message:
Error flask
You don't seem to have a generator with the name flask installed.
You can see available generators with npm search yeoman-generator and then install them with npm install [name].
To see the 22 registered generators run yo with the `--help` option.
I do as it tells me by running yo --help and discover that the flask generator is not there.
I try this with sudo npm install -g generator-angular-flask and the problem is recreated with Angular Flask. I'm assuming this is going to happen for all the generators which is why I've titled it as Yeoman not recognizing new npm installs.
Does anyone know why this has happened?
A workaround, but does solve the problem:
npm link generator-angular-flask
(as does just installing the module locally)
Usually it is a $NODE_PATH issue, but rather then guessing, run:
yo doctor
and follow the instructions!
Node path is the issue.
To setup path:
export NODE_PATH=$HOME/.node/lib/node_modules/
In my case node is in HOME directory.
I was having a similar issue. Basically Yeoman was showing No installed generators, even if I fired up yeoman and installed the generator again still no luck to run it.
I typed yo doctor and did the changes it recommends, but still no luck...
I then ran
export NODE_PATH=$HOME/.node/lib/node_modules/
Then I fired up Yeoman and still no luck.
I then decide run yo doctor again and voila! New errors. I then saw the final recommendation by the yo doctor so I decide to run it:
export NODE_PATH=$NODE_PATH:/Users/slickstyles/.npm-global/lib/node_modules
After I type yo and guess what I see? All my installed yeoman generators showing and working marvelously.
You can use:
yo doctor
and you will not something like:
npm root value is not in your NODE_PATH
[Info]
NODE_PATH = /home/action/.node/lib/node_modules/
npm root = /home/action/.parts/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/action/.parts/lib/node_modules
Or run this command
echo "export NODE_PATH=$NODE_PATH:/home/action/.parts/lib/node_modules" >> ~/.bashrc && source ~/.bashrc
and try again:
npm install -g generator-webapp
Check if you have NODE_PATH set. To set it open a terminal and type (assuming you have node under /opt/node/ and use bash shell)
echo "export NODE_PATH=/opt/node:/opt/node/lib/node_modules" >> ~/.bashrc && . ~/.bashrc
Once done, run yo doctor. If all is ok, run yo to see your installed generators.