因爲好久前已經安裝好了brew了,如今經過brew安裝nodenode
brew install node
安裝node後使用npm的時候出現錯誤,錯誤以下git
sbei215:bin alex.kong$ ./npm module.js:338 throw err; ^ Error: Cannot find module '/usr/local/lib/node_modules/npm/bin/node_modules/npm/bin/npm-cli.js' at Function.Module._resolveFilename (module.js:336:15) at Function.Module._load (module.js:278:25) at Function.Module.runMain (module.js:501:10) at startup (node.js:129:16) at node.js:814:3
經過網上查詢後解決辦法github
修改/usr/local/lib/node_modules/npm/bin/npm文件因爲npm_cli.js 位於 /usr/local/lib/node_modules/npm/bin #!/bin/sh (set -o igncr) 2>/dev/null && set -o igncr; # cygwin encoding fix basedir=`dirname "$0"` case `uname` in *CYGWIN*) basedir=`cygpath -w "$basedir"`;; esac if [ -x "$basedir/node.exe" ]; then "$basedir/node.exe" "$basedir/node_modules/npm/bin/npm-cli.js" "$@" else node "$basedir/npm-cli.js" "$@" fi 第二步 vim ./.bash_profile export PATH="/usr/local/lib/node_modules/npm/bin:$PATH" export NODE_PATH="/usr/local/lib/node"
到了最後一步安裝apidocnpm
npm install apidoc -g
結果又出現錯誤vim
ERR! Please try running this command again as root/Administrator. npm ERR! Darwin 14.5.0 npm ERR! argv "node" "/usr/local/lib/node_modules/npm/bin/npm-cli.js" "install" "apidoc" "-g" npm ERR! node v0.12.4 npm ERR! npm v2.10.1 npm ERR! Uncaught, unspecified "error" event. npm ERR! npm ERR! If you need help, you may report this error at: npm ERR! <https://github.com/npm/npm/issues> npm ERR! Please include the following file with any support request: npm ERR! /usr/local/lib/node_modules/npm/npm-debug.log
看到上面提示果斷使用root執行安裝,成功了api
如今github上面的例子運行一下bash
apidoc example/ -o doc/ so easy
參考文章:this
https://github.com/apidoc/apidocdebug
http://stackoverflow.com/questions/27824675/npm-cannot-find-npm-cli-module-after-yosemite-upgradeblog
http://apidocjs.com/