2013-08-06 47 views
36

我有一個Yeoman發生器的問題。如果我運行「npm install [generator-name] -g」,它們安裝得很好。然而,當我嘗試運行「喲[generator-name] yeoman似乎無法找到生成器。如果我只是運行」喲「,它也不會列在我的其他生成器之中。我試過了一堆生成器,結果是永遠不變的。爲什麼我的Yeoman發電機安裝在錯誤的地方?

有點調查的一點我發現下載的發電機被放置在

/usr/local/lib/node_modules/ 

但我的其他發電機被放置在

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

這裏以後是一個圖像它在我的機器上看起來如何http://i.imgur.com/DxWTYHb.png,我正在運行OSX案件很重要。看起來有點不對勁 - 但我無法弄清楚。

不知道這是否會有所幫助,但沖泡的醫生和$ NODE_PATH返回任何結果,而$ PATH返回:

-bash: 
/usr/local/share/npm/bin: 
/Users/marcus/.rvm/gems/ruby-2.0.0-p247/bin: 
/Users/marcus/.rvm/gems/[email protected]/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


我試了一下埃迪·蒙赫JR建議和現在我的角生成器工作正常。然而,當我安裝另一臺發電機(chrome-extension)時,他們堅持認爲它沒有安裝/找到。

當我運行LS $(NPM配置get前綴)/ lib目錄/ node_modules我得到這個:

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

而且NPM列表-g回報這個(我切出了大量的通用的東西)

/usr/local/lib 
├─┬ [email protected] 
├─┬ [email protected] 
│ └─┬ [email protected] 
├─┬ [email protected] 
│ └─┬ [email protected] 
├─┬ [email protected] 
│ └─┬ [email protected] 
├─┬ [email protected] 
│ └─┬ [email protected] 
├─┬ [email protected] 
├─┬ [email protected] 
└─┬ [email protected] 

我奇怪的部份是,如果我跑喲--help我得到發電機

的怪列表210
[?] 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! 

回答

50

我試着在Ubuntu的精確32流浪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 

由自耕農醫生建議的修復工作作爲標榜。

+2

你是怎麼跑[Yeoman Doctor]的?似乎無法弄清楚。 – anderssonma

+0

我會將您的答覆標記爲答案,因爲我確信我的問題是相似的。我刪除了NPM並將Node.JS更新爲最新版本。然後我使用這個SH腳本[鏈接](https://npmjs.org/install.sh)再次安裝了NPM。該腳本找到並刪除了一些奇怪的NPM路徑,現在它又重新正常運行。乾杯! – anderssonma

+5

要運行yeoman醫生,你需要'找到doctor.js'(和我一起,這是一個以'.../yo/scripts/doctor.js'結尾的路徑,並且只需要運行它。我運行喲是重新安裝喲之前在'rm -rf/usr/local/lib/node_modules/yo'之後用'npm cache clean'重新開始。 –

1

聽起來像你的npm可能會失去作用。檢查安裝的東西: npm config獲取前綴 是否您希望安裝軟件包?那是他們目前安裝的地方嗎?

要列出什麼在那裏:

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

,將列出了全球的裝機NPM包。

npm list -g 

將列出當前安裝的東西。確保喲和發電機列在頂層。

要刪除喲東西,並開始了:

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

這應該解決的事情。

+0

感謝您的回覆!我現在無法訪問我的工作計算機,但明天我會試試看。 – anderssonma

+0

嗯我的角生成器現在工作,我已經嘗試了鉻擴展和骨幹生成器,但沒有運氣,但是 - Yeoman似乎無法找到它。我已經更新了我的問題。 – anderssonma

+0

是的,因爲我刪除了'喲發生器'的東西,我可以'npm update' &&'npm -g update'沒有再次警告。我想結賬yeoman工作流程。 –

7

我卸載自耕農完全,然後重新安裝它

npm remove -g yo 
npm install -g yo 

這個固定我的問題與缺失的角度發電機。

24

我遇到了這個問題,我希望它能幫助別人。 我相信升級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 

現在我指着node_modules目錄 因此,所有的新的NPM模塊I安裝找到合適的位置:在/ usr/local/share下/ NPM/lib中/ node_modules

但是,並非yo

我跑了which yo和我的道路是

/usr/local/bin/yo 

這個二進制文件指向OLDnode_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 

,現在新的「喲」引用正確node_modules安裝基地

source ~/.bash_profile 

這時我們可以看到喲是從正確的點參考

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

未來所有的發電機會放置在正確的node_modules目錄中,並且yo將能夠毫無問題地找到它們!

+0

聽起來很像我的錯誤,我嘗試了** npm remove -g yo **但沒有成功,但是我沒有做的是運行* * rm/usr/local/bin/yo **,我不確定這是否能解決問題,但謝謝! – anderssonma

+0

這對我有用! '工作,下面這一行:'PATH = $ {PATH}:〜/ .node/bin',不要忘記重新啓動提示讓更改生效。 – nilsi

相關問題