【问题标题】:Why are my Yeoman generators installing in the wrong place?为什么我的 Yeoman 发电机安装在错误的位置?
【发布时间】:2013-08-07 12:22:25
【问题描述】:

我对 Yeoman 生成器有疑问。如果我运行“npm install [generator-name] -g”,它们安装得很好。但是,当我尝试运行“yo [generator-name] 时,yeoman 似乎找不到生成器。如果我只运行“yo”,它也不会在我的其他生成器中列出。我尝试了一堆生成器,结果总是一样的。

经过一番调查,我发现下载的生成器放置在

/usr/local/lib/node_modules/

但是我的其他生成器都放在了

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

这是它在我的机器上的外观图像http://i.imgur.com/DxWTYHb.png,我正在运行 OSX,以防万一。对我来说似乎有什么问题 - 但我无法弄清楚。

不确定这是否有帮助,但 brew doctor 和 $NODE_PATH 在 $PATH 返回时什么也不返回:

-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


更新


我尝试了 Eddie Monge Jr 的建议,现在我的角度发生器工作正常。但是,当我安装另一个生成器(chrome-extension)时,yeoman 坚持认为它没有安装/找到。

当我运行 ls $(npm config get prefix)/lib/node_modules 我得到这个:

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

并且 npm list -g 返回这个(我删掉了很多通用的东西)

/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

对我来说奇怪的是,如果我运行 yo --help 我会得到一个奇怪的生成器列表

[?] 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!

【问题讨论】:

    标签: npm yeoman


    【解决方案1】:

    我尝试在 Ubuntu 精确32 vagrant vm 上安装 Yeoman。我遇到了同样的问题:Yeoman 没有找到我安装的生成器,尽管在安装这些生成器的过程中没有错误。文件已就位,权限似乎没问题。

    上述解决方案对我不起作用。

    我跑了

    yo doctor
    

    看看出了什么问题,事实证明,问题出在以下:

    [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
    

    Yeoman Doctor 建议的修复方法与宣传的一样有效。

    【讨论】:

    • 你是如何经营 [Yeoman Doctor] 的?似乎无法弄清楚。
    • 我会将您的回复标记为答案,因为我很确定我的问题与此类似。我删除了 NPM 并将 Node.JS 更新到了最新版本。然后我使用这个 SH 脚本link 再次安装了 NPM。该脚本找到并删除了几个奇怪的 NPM 路径,现在它再次正常运行。干杯!
    • 要运行 yeoman doctor,你需要 locate doctor.js(对我来说,这是一条以 .../yo/scripts/doctor.js 结尾的路径,只需使用 node 运行它。另外,最终帮助我运行 yo 的是从npm cache clean 重新开始(在rm -rf /usr/local/lib/node_modules/yo 之后,在重新安装之前)。
    【解决方案2】:

    我遇到了这个问题,我希望它会对某人有所帮助。 我相信升级 NPM 给我带来了这个初始问题。

    /usr/local/lib/node_modules
    

    过去是我的许多模块的位置。自从升级节点后,目录变成了

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

    什么时候我会运行新的安装,例如:

    npm install -g grunt-cli
    

    自从我从命令行运行 grunt 后,它就不会“找到”它(那是因为它不在我的新 node_modules 目录中)。我在我的 .bash_profile 中设置了这个:

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

    现在我指向 new node_modules 目录 所以我安装的所有新 npm 模块都找到了正确的位置:/usr/local/share/npm/lib/node_modules

    但不是yo

    我跑了which yo,我的路径是

    /usr/local/bin/yo
    

    这个二进制文件指向 OLD node_modules 安装 @

    /usr/local/lib/node_modules
    

    我的解决方案是这样做

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

    yo 的旧引用已经不复存在,现在我可以这样做了

    npm install -g yo
    

    这会将其添加到新的node_modules 位置

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

    现在新的 'yo' 引用了正确的 node_modules 安装基础

    source ~/.bash_profile
    

    然后我们可以看到 yo 是从正确的位置引用的

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

    所有未来的生成器都将放置在正确的node_modules 目录中,yo 将能够毫无问题地找到它们!

    【讨论】:

    • 听起来很像我遇到的错误。我确实尝试了 npm remove -g yo 几次但没有成功。我没有做的是运行 rm /usr/local/bin/yo,但我不确定这是否会解决问题。不过谢谢!
    • 这是为我准备的!我还在 bash_profile 添加了一个符号链接以使 yo 工作。以下行:PATH=${PATH}:~/.node/bin 并且不要忘记重新启动提示以使更改生效。
    【解决方案3】:

    我完全卸载了 yeoman,然后重新安装了它

    npm remove -g yo
    npm install -g yo
    

    这解决了我缺少角度生成器的问题。

    【讨论】:

      【解决方案4】:

      听起来你的 npm 可能不正常。检查东西的安装位置: npm 配置获取前缀 那是您期望安装软件包的地方吗?这是它们当前的安装位置吗?

      列出里面的内容:

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

      这将列出全局安装的 npm 包。

      npm list -g
      

      会列出当前安装的东西。确保 yo 和生成器列在顶层。

      删除 yo 的东西并重新开始:

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

      这应该可以解决问题。

      【讨论】:

      • 感谢您的回复!我现在无法使用我的工作计算机,但我明天会试一试。
      • 嗯,我的角度生成器现在可以工作了,但是我已经尝试了 chrome-extension 和骨干生成器但没有运气 - Yeoman 似乎找不到它。我已经更新了我上面的问题。
      • 是的,因为我删除了yo generator 的东西,我可以npm update && npm -g update 再次没有警告。我想查看 yeoman 工作流程。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多