我是node,npm,socket.io的新手。找到很多相當有用的指南,但我遇到了一些我不明白原因的錯誤,希望你能幫助我。嘗試全局安裝socket.io時出現錯誤
npm install socket.io -g
回報......
npm http GET https://registry.npmjs.org/socket.io
npm http 304 https://registry.npmjs.org/socket.io
npm ERR! error installing [email protected]
npm ERR! error rolling back [email protected] Error: EACCES, unlink '/usr/local/lib/node_modules/socket.io/.npmignore'
npm ERR! Error: EACCES, unlink '/usr/local/lib/node_modules/socket.io/.npmignore'
npm ERR! Report this *entire* log at:
npm ERR! <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR! <[email protected]>
npm ERR!
npm ERR! System Darwin 10.8.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "socket.io" "-g"
npm ERR! cwd /Users/Kinglee
npm ERR! node -v v0.6.14
npm ERR! npm -v 1.1.0-beta-4
npm ERR! path /usr/local/lib/node_modules/socket.io/.npmignore
npm ERR! code EACCES
npm ERR! message EACCES, unlink '/usr/local/lib/node_modules/socket.io/.npmignore'
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /Users/Kinglee/npm-debug.log
然而,當我做了npm install socket.io
,沒有錯誤,一切都很好。
對不起忘了在這裏補充此信息...
我真的試圖sudo npm install socket.io
並沒有錯誤安裝,但是當我嘗試cd ~/node_modules
,我沒有看到socket.io,這項事業'socket.io not found' error
當我嘗試做require('socket.io')
像我效法這裏本教程(http://blog.koostudios.com/?p=470)
一種迷茫的同胞在這裏:/
呵呵,我忘了補充一點,我實際上試過'sudo npm install socket.io -g',它安裝的很好。但是當我cd到〜/ node_modules時,我看不到socket.io。當我嘗試在我正在關注的教程(http://blog.koostudios.com/?p=470)上執行'node main.js'時,會導致錯誤'socket.io not found'。 – 2012-04-01 21:26:52
在啓動node之前,您可能需要在'NODE_PATH'環境變量中添加'/ usr/local/lib/node_modules /',或在腳本中修改'require.paths'。我更喜歡環境變量,因爲它不會將系統環境知識硬編碼到程序中。嘗試運行:'NODE_PATH =/usr/local/lib/node_modules node foo.js' - 這是,在'node'命令之前加上'NODE_PATH'分配。如果可行,那麼在'〜/ .bashrc'文件中添加'export NODE_PATH =/usr/local/lib/node_modules'。 (並報告回來;我會清理答案和評論...) – sarnold 2012-04-01 21:35:35
好的,這是我做的... npm rm socket.io, node main.js // return找不到模塊'socket.io '這是正確的, sudo npm install socket.io -g //一切都很順利, ..檢查是否socket.io在〜/ node_modules .. //不是, NODE_PATH =/usr/local/lib/node_modules節點main.js // Ooo,它的工作原理, ..添加到.bash_profile的路徑, node main.js //很好用。非常感謝, Argh我在'控制檯,在這行'socket = io.connect'http:// localhost'「,'我沒有定義錯誤',我懷疑這個網址對我的設置是錯誤的..嗯 – 2012-04-01 21:57:59