为什么我的 Yeoman 生成器安装在错误的位置? [英] Why are my Yeoman generators installing in the wrong place?

查看:50
本文介绍了为什么我的 Yeoman 生成器安装在错误的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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/

这是它在我的机器上的外观图像http://i.imgur.com/DxWTYHb.png,以防万一,我正在运行 OSX.看起来我有问题 - 但我想不通.

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.

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

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


更新

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

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.

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

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

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

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

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

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!

推荐答案

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

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.

我跑了

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

Yeoman Doctor 建议的修复方法如宣传的那样奏效.

The fix suggested by the Yeoman Doctor worked as advertised.

这篇关于为什么我的 Yeoman 生成器安装在错误的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆