NPM and node-gyp

pm2 中会使用到 fsevents,node-gyp rebuild fsevents 时,会遇到下面这样的错误:

1
user "root" does not have permission to access the dev dir

网上找到的讨论,说 node-gyp 不能用在 sudo 下,由于 Mac 上 pkg 安装的 node 需要 sudo 执行 npm,所以这样:

1
2
sudo chown -R `whoami` ~/.npm
sudo chown -R `whoami` /usr/local/lib/node_modules

之后就不再需要 sudo 安装 npm 了。

重新安装 pm2 ,到了 fsevents 时, node-gyp rebuild 能运行了,但到了一半,错误变成这样:

1
2
3
4
5
6
7
8
make: *** [Release/obj.target/fse/fsevents.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:267:23)
gyp ERR! stack at ChildProcess.EventEmitter.emit (events.js:110:17)
gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:1046:12)
gyp ERR! System Darwin 13.3.0
gyp ERR! command "node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"

但是安装是成功的…… pm2 可以正常使用。

为探究竟,费尽半天辛苦,发现原来是 node 0.11.13 的问题……可以看这里https://github.com/pipobscure/fsevents/pull/26

无言以对。