2013年5月27日 星期一

[nodejs] 安裝 node-gitteh 失敗過程

因為有人說,因為大家都是 *nix like,只有 windows 不是,所以有問題會很慢才解決,我當場就把作業系統給換成 ubuntu。

gitteh 是一個讓 nodejs 可以用程式的方式來執行 git 指令,因為我想要自動偵測新檔案出現,就自動 commit,所以腦筋就動到這東西來了。也有人說,只要會用 shell 指令,把 stdout 導出來,再做一些文字解析的工作,也就完成一樣的事,不過,就是怕改版文字會跑掉。所以,有人就寫了 libgit2 的 C 語言函式庫讓人使用,再由各語言呼叫 C 函式庫來滿足大家的需求,例如 nodejs、python。而 nodejs 的 bindings 就叫做 gitteh。

libgit2 的網站 http://libgit2.github.com/

gitteh 的網站 https://github.com/libgit2/node-gitteh

安裝 gitteh (在 ubuntu)

在 github 這裡,就只有說 npm  install gitteh 就好,看了就很高興。

BUT! 人生就怕這個字。

執行 npm install gitteh 遇到

hadoop@ubuntu:~/nodejs/myapp/src$ npm install gitteh
npm http GET https://registry.npmjs.org/gitteh
npm http 304 https://registry.npmjs.org/gitteh

> gitteh@0.1.0 preinstall /home/hadoop/nodejs/myapp/src/node_modules/gitteh
> node-waf configure --use-bundled-libgit2

sh: 1: node-waf: not found
npm ERR! weird error 127
npm ERR! not ok code 0

 

以為是少 node-waf,於是下指令 npm install node-waf

結果

hadoop@ubuntu:~/nodejs/myapp/src$ npm install node-waf
npm http GET https://registry.npmjs.org/node-waf
npm http 404 https://registry.npmjs.org/node-waf
npm ERR! 404 'node-waf' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it
npm ERR! 404
npm ERR! 404 Maybe try 'npm search waf'
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, or http url, or git url.

npm ERR! System Linux 3.5.0-17-generic
npm ERR! command "/home/hadoop/.nvm/v0.10.7/bin/node" "/home/hadoop/.nvm/v0.10.7/bin/npm" "install" "node-waf"
npm ERR! cwd /home/hadoop/nodejs/myapp/src
npm ERR! node -v v0.10.7
npm ERR! npm -v 1.2.21
npm ERR! code E404
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     /home/hadoop/nodejs/myapp/src/npm-debug.log
npm ERR! not ok code 0

唉~~

試了 http://stackoverflow.com/questions/13784551/how-to-install-node-gitteh-module-from-npm-nodejs-0-8-x

npm install git://github.com/jmendeth/node-gitteh.git
失敗
再試 https://github.com/libgit2/node-gitteh/issues/21 還是失敗
我想試試先安裝 libgit2,npm install libgit2,結果找不到。
npm search libgit2 有找到一個 nodegit,就來試試,npm install nodegit。
跑了一大串之後得到


> nodegit@0.0.79 install /home/hadoop/nodejs/myapp/src/node_modules/nodegit
> node install.js


[nodegit] Downloading libgit2 dependency.
[nodegit] Building libgit2 dependency.
/usr/bin/env: cmake: No such file or directory
npm ERR! weird error 127
npm ERR! not ok code 0


 


於是 sudo apt-get install cmake 後,再一次,結果換 g++ 找不到。依稀記得有個 build-essential,就裝它吧。 sudo apt-get install build-essential 。再一次安裝 nodegit。好像成功了,雖然有 WARN



npm WARN package.json cli-table@0.2.0 No repository field.
nodegit@0.0.79 node_modules/nodegit
├── async@0.2.8
├── request@2.9.203
├── tar@0.1.17 (inherits@1.0.0, block-stream@0.0.6, fstream@0.1.22)
├── fs-extra@0.6.0 (jsonfile@0.0.1, ncp@0.4.2, mkdirp@0.3.5, rimraf@2.1.4)
└── node-gyp@0.8.5 (which@1.0.5, osenv@0.0.3, graceful-fs@1.2.1, rimraf@2.1.4, semver@1.1.4, mkdirp@0.3.5, glob@3.2.1, fstream@0.1.22, npmlog@0.0.2, nopt@2.1.1, minimatch@0.2.12)


 


又回到執行 npm install gitteh,登登!



> gitteh@0.1.0 preinstall /home/hadoop/nodejs/myapp/src/node_modules/gitteh
> node-waf configure --use-bundled-libgit2


sh: 1: node-waf: not found
npm ERR! weird error 127
npm ERR! not ok code 0


 


此路不通啊。


下載 git clone https://github.com/libgit2/node-gitteh.git 來安裝試試



hadoop@ubuntu:~/nodejs/myapp/src/node-gitteh$ node install.js


module.js:340
    throw err;
          ^
Error: Cannot find module 'async'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/home/hadoop/nodejs/myapp/src/node-gitteh/install.js:1:75)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)


 


看來是 async 找不到,就裝一下,




hadoop@ubuntu:~/nodejs/myapp/src/node-gitteh$ npm install async -g
npm http GET https://registry.npmjs.org/async
npm http 304 https://registry.npmjs.org/async
npm WARN package.json github-url-from-git@1.1.1 No repository field.
npm WARN package.json assert-plus@0.1.2 No repository field.
npm WARN package.json ctype@0.5.2 No repository field.
async@0.2.8 /home/hadoop/.nvm/v0.10.7/lib/node_modules/async


 


再試發現裝到 global 好像沒反應,就改裝在工作目錄。



hadoop@ubuntu:~/nodejs/myapp/src/node-gitteh$ node install.js


module.js:340
    throw err;
          ^
Error: Cannot find module 'async'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/home/hadoop/nodejs/myapp/src/node-gitteh/install.js:1:75)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
hadoop@ubuntu:~/nodejs/myapp/src/node-gitteh$ npm install async
npm http GET https://registry.npmjs.org/async
npm http 304 https://registry.npmjs.org/async
async@0.2.8 node_modules/async


hadoop@ubuntu:~/nodejs/myapp/src/node-gitteh$


npm install async
npm http GET https://registry.npmjs.org/async
npm http 304 https://registry.npmjs.org/async
async@0.2.8 node_modules/asynchadoop@ubuntu:~/nodejs/myapp/src/node-gitteh$
hadoop@ubuntu:~/nodejs/myapp/src/node-gitteh$
hadoop@ubuntu:~/nodejs/myapp/src/node-gitteh$
hadoop@ubuntu:~/nodejs/myapp/src/node-gitteh$
hadoop@ubuntu:~/nodejs/myapp/src/node-gitteh$ node install.js
[gitteh] Downloading libgit2 dependency.
Submodule 'deps/libgit2' (git://github.com/libgit2/libgit2.git) registered for path 'deps/libgit2'
Cloning into 'deps/libgit2'...


中間省略


[gitteh] Building native module.
/bin/sh: 1: ./node_modules/.bin/node-gyp: not found


又少 node-gyp。再來 npm install node-gyp



hadoop@ubuntu:~/nodejs/myapp/src/node-gitteh$ npm install node-gyp
npm http GET https://registry.npmjs.org/node-gyp
npm http 304 https://registry.npmjs.org/node-gyp
npm http GET https://registry.npmjs.org/tar
npm http GET https://registry.npmjs.org/fstream
npm http GET https://registry.npmjs.org/graceful-fs
npm http GET https://registry.npmjs.org/minimatch
npm http GET https://registry.npmjs.org/mkdirp
npm http GET https://registry.npmjs.org/nopt
npm http GET https://registry.npmjs.org/npmlog
npm http GET https://registry.npmjs.org/osenv
npm http GET https://registry.npmjs.org/request
npm http GET https://registry.npmjs.org/rimraf
npm http GET https://registry.npmjs.org/semver
npm http GET https://registry.npmjs.org/which
npm http GET https://registry.npmjs.org/glob
npm http 304 https://registry.npmjs.org/graceful-fs
npm http 304 https://registry.npmjs.org/minimatch
npm http 304 https://registry.npmjs.org/fstream
npm http 304 https://registry.npmjs.org/nopt
npm http 304 https://registry.npmjs.org/npmlog
npm http 304 https://registry.npmjs.org/osenv
npm http 304 https://registry.npmjs.org/request
npm http 200 https://registry.npmjs.org/tar
npm http 304 https://registry.npmjs.org/rimraf
npm http 304 https://registry.npmjs.org/semver
npm http 304 https://registry.npmjs.org/which
npm http 304 https://registry.npmjs.org/glob
npm http 304 https://registry.npmjs.org/mkdirp
npm http GET https://registry.npmjs.org/ansi
npm http GET https://registry.npmjs.org/abbrev
npm http GET https://registry.npmjs.org/lru-cache
npm http GET https://registry.npmjs.org/sigmund
npm http GET https://registry.npmjs.org/inherits
npm http GET https://registry.npmjs.org/inherits
npm http GET https://registry.npmjs.org/inherits
npm http GET https://registry.npmjs.org/block-stream
npm http 304 https://registry.npmjs.org/abbrev
npm http 304 https://registry.npmjs.org/sigmund
npm http 304 https://registry.npmjs.org/lru-cache
npm http 304 https://registry.npmjs.org/ansi
npm http 304 https://registry.npmjs.org/inherits
npm http 304 https://registry.npmjs.org/inherits
npm http 304 https://registry.npmjs.org/block-stream
npm http 304 https://registry.npmjs.org/inherits
node-gyp@0.8.5 node_modules/node-gyp
├── which@1.0.5
├── osenv@0.0.3
├── graceful-fs@1.2.1
├── rimraf@2.1.4
├── semver@1.1.4
├── mkdirp@0.3.5
├── request@2.9.203
├── nopt@2.1.1 (abbrev@1.0.4)
├── fstream@0.1.22 (inherits@1.0.0)
├── minimatch@0.2.12 (sigmund@1.0.0, lru-cache@2.3.0)
├── npmlog@0.0.2 (ansi@0.1.2)
├── tar@0.1.17 (inherits@1.0.0, block-stream@0.0.6)
└── glob@3.2.1 (inherits@1.0.0)


再試 node install.js



/home/hadoop/.node-gyp/0.10.7/deps/uv/include/uv.h:1411:15: error:   initializing argument 4 of ‘int uv_queue_work(uv_loop_t*, uv_work_t*, uv_work_cb, uv_after_work_cb)’ [-fpermissive]
make: *** [Debug/obj.target/gitteh/src/repository.o] Error 1
make: Leaving directory `/home/hadoop/nodejs/myapp/src/node-gitteh/build'
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/home/hadoop/nodejs/myapp/src/node-gitteh/node_modules/node-gyp/lib/build.js:256:23)
gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:789:12)
gyp ERR! System Linux 3.5.0-17-generic
gyp ERR! command "node" "/home/hadoop/nodejs/myapp/src/node-gitteh/node_modules/.bin/node-gyp" "build"
gyp ERR! cwd /home/hadoop/nodejs/myapp/src/node-gitteh
gyp ERR! node -v v0.10.7
gyp ERR! node-gyp -v v0.8.5
gyp ERR! not ok


 


還是失敗。等等,會不會忘了 preinstall?結果沒用…。


於是我就放棄了,試試看 http://www.pygit2.org/

沒有留言:

張貼留言