Why are my Yeoman generators installing in the wrong place?

前端 未结 4 1620
孤独总比滥情好
孤独总比滥情好 2020-12-08 10:02

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 s

相关标签:
4条回答
  • 2020-12-08 10:10

    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.

    0 讨论(0)
  • 2020-12-08 10:21

    I uninstalled yeoman entirely, then re-installed it

    npm remove -g yo
    npm install -g yo
    

    This fixed my problem with missing angular generators.

    0 讨论(0)
  • 2020-12-08 10:28

    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!

    0 讨论(0)
  • 2020-12-08 10:33

    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.

    0 讨论(0)
提交回复
热议问题