LoginSignup
4
3

More than 5 years have passed since last update.

Node.jsのバージョンアップ後にhomebridgeを起動しようとしたらハマった

Posted at

環境

$ lsb_release -a
No LSB modules are available.
Distributor ID: Raspbian
Description:    Raspbian GNU/Linux 8.0 (jessie)
Release:    8.0
Codename:   jessie
$ node -v
v9.6.1
$ npm -v
5.6.0

Raspberry Pi上でNode.jsのバージョンアップ後にhomebridgeを起動しようとすると以下のエラーが出ました。

$ homebridge
/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/node_modules/mdns/lib/dns_sd.js:35
    throw ex;
    ^

Error: The module '/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/node_modules/mdns/build/Release/dns_sd_bindings.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 46. This version of Node.js requires
NODE_MODULE_VERSION 59. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).
    at Object.Module._extensions..node (module.js:691:18)
    at Module.load (module.js:575:32)
    at tryModuleLoad (module.js:515:12)
    at Function.Module._load (module.js:507:3)
    at Module.require (module.js:606:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/node_modules/mdns/lib/dns_sd.js:24:20)
    at Module._compile (module.js:662:30)
    at Object.Module._extensions..js (module.js:673:10)
    at Module.load (module.js:575:32)

どうやら異なるバージョンでコンパイルしたことが原因のようです。npm rebuild or npm installで解決しそうです。さっそくnpm rebuildを試してみると。。

$ cd /usr/local/lib/node_modules/homebridge
$ npm rebuild

> curve25519-n2@1.1.3 install /usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/node_modules/curve25519-n2
> node-gyp rebuild

gyp ERR! clean error 
gyp ERR! stack Error: EACCES: permission denied, rmdir 'build'
gyp ERR! System Linux 4.9.35-v7+
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/node_modules/curve25519-n2
gyp ERR! node -v v9.6.1
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok 
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! curve25519-n2@1.1.3 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the curve25519-n2@1.1.3 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/pi/.npm/_logs/2018-03-07T11_56_05_707Z-debug.log

エラー。権限不足でbuildディレクトリが削除できないのが原因のようです。sudoで実行してもダメ。ディレクトリの権限を確認してみると。。

$ cd /usr/local/lib/node_modules/homebridge
$ ls -la
合計 76
drwxr-sr-x 7 nobody pi  4096  3月  7 20:59 .
drwxr-sr-x 7 nobody pi  4096  3月  7 20:59 ..
drwxr-sr-x 2 nobody pi  4096 11月 25 15:54 .github
-rw-r--r-- 1 nobody pi   204 11月 30  2016 .npmignore
-rw-r--r-- 1 nobody pi 10172  2月 14  2016 LICENSE
-rw-r--r-- 1 nobody pi 11702 11月  2 07:13 README.md
drwxr-sr-x 2 nobody pi  4096  3月  7 20:59 bin
-rw-r--r-- 1 nobody pi   599 10月 21 08:32 config-sample.json
drwxr-sr-x 3 nobody pi  4096  7月 27  2016 devPlugins
drwxr-sr-x 3 nobody pi  4096 11月 25 15:54 lib
drwxr-sr-x 9 nobody pi  4096 11月 25 15:54 node_modules
-rw-r--r-- 1 root   pi  9197  3月  7 20:59 package-lock.json
-rw-r--r-- 1 root   pi  1818 11月 25 15:54 package.json

nobodyという所有者が悪さをしているようです。buildディレクトリがどこにあるのかよくわからなかったので、homebridgeディレクトリ以下をまるごとnobodyからpiユーザに所有者変更してみます。

$ sudo chown -R pi /usr/local/lib/node_modules/homebridge
$ ls -la
合計 76
drwxr-sr-x 7 pi     pi  4096  3月  7 20:59 .
drwxr-sr-x 7 nobody pi  4096  3月  7 20:59 ..
drwxr-sr-x 2 pi     pi  4096 11月 25 15:54 .github
-rw-r--r-- 1 pi     pi   204 11月 30  2016 .npmignore
-rw-r--r-- 1 pi     pi 10172  2月 14  2016 LICENSE
-rw-r--r-- 1 pi     pi 11702 11月  2 07:13 README.md
drwxr-sr-x 2 pi     pi  4096  3月  7 20:59 bin
-rw-r--r-- 1 pi     pi   599 10月 21 08:32 config-sample.json
drwxr-sr-x 3 pi     pi  4096  7月 27  2016 devPlugins
drwxr-sr-x 3 pi     pi  4096 11月 25 15:54 lib
drwxr-sr-x 9 pi     pi  4096 11月 25 15:54 node_modules
-rw-r--r-- 1 pi     pi  9197  3月  7 20:59 package-lock.json
-rw-r--r-- 1 pi     pi  1818 11月 25 15:54 package.json

これでどうだっ。。

$ npm rebuild

> curve25519-n2@1.1.3 install /usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/node_modules/curve25519-n2
> node-gyp rebuild

make: Entering directory '/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/node_modules/curve25519-n2/build'
  CXX(target) Release/obj.target/curve/node_curve.o
  SOLINK_MODULE(target) Release/obj.target/curve.node
  COPY Release/curve.node
make: Leaving directory '/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/node_modules/curve25519-n2/build'

(省略)

いけた!!改めてhomebridgeを起動してみると。。

$ homebridge

*** WARNING *** The program 'node' uses the Apple Bonjour compatibility layer of Avahi.
*** WARNING *** Please fix your application to use the native API of Avahi!
*** WARNING *** For more information see <http://0pointer.de/avahi-compat?s=libdns_sd&e=node>
*** WARNING *** The program 'node' called 'DNSServiceRegister()' which is not supported (or only supported partially) in the Apple Bonjour compatibility layer of Avahi.
*** WARNING *** Please fix your application to use the native API of Avahi!
*** WARNING *** For more information see <http://0pointer.de/avahi-compat?s=libdns_sd&e=node&f=DNSServiceRegister>

(中略)

[2018-3-7 21:31:59] Homebridge is running on port 51826.

homebridge無事起動できました!

まとめ

Node.jsのバージョン管理ツール導入しようかな。。

参考リンク

4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3