Why are my Yeoman generators installing in the wrong place?

前端 未结 4 1643
孤独总比滥情好
孤独总比滥情好 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: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!

提交回复
热议问题