mozyのかきおき

mozyの読書感想文や思考置き場

Zettajs はnodeのバージョンが9だと動かない

Hello World Zetta
を試していたところ、以下のようなエラーでコケた。 

util.js:948
    throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'superCtor', 'Function');
    ^

TypeError [ERR_INVALID_ARG_TYPE]: The "superCtor" argument must be of type Function
    at Object.inherits (util.js:948:11)
    at Object.<anonymous> (/Users/moyz/Test/zettajs-test/node_modules/spdy/lib/spdy/connection.js:86:6)
    at Module._compile (module.js:660:30)
    at Object.Module._extensions..js (module.js:671:10)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)
    at Module.require (module.js:604:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/mozy/Test/zettajs-test/node_modules/spdy/lib/spdy.js:20:19)

あーコレはnodeのバージョンの問題だなと思ったので
nodebrew list でインストールしているnodeのバージョンを確認した。
今回は、 運よくv6.11.0がインストールしてあったのでこちらを使用した。

direnvを使ってディレクトリごとに環境を変えているので、今回も、
direnv edit ..envrcファイル内に PATH_add ~/.nodebrew/node/v6.11.0/bin と記載して解決。

動作確認

$ node server.js 
(node:6554) DeprecationWarning: process.EventEmitter is deprecated. Use require('events') instead.
Mar-21-2018 12:47:23 [server] Server (mozy) mozy listening on http://127.0.0.1:1337
Zetta is running at http://127.0.0.1:1337
$curl http://127.0.0.1:1337
{"class":["root"],"links":[{"rel":["self"],"href":"http://127.0.0.1:1337/"},{"title":"mozy","rel":["http://rels.zettajs.io/server"],"href":"http://127.0.0.1:1337/servers/mozy"},{"rel":["http://rels.zettajs.io/events"],"href":"ws://127.0.0.1:1337/events"},{"rel":["http://rels.zettajs.io/peer-management"],"href":"http://127.0.0.1:1337/peer-management"}],"actions":[{"name":"query-devices","method":"GET","href":"http://127.0.0.1:1337/","type":"application/x-www-form-urlencoded","fields":[{"name":"server","type":"text"},{"name":"ql","type":"text"}]}]}% 

いい感じ。実験完了。動いてよかった。❤︎