LoginSignup
6
6

More than 5 years have passed since last update.

優秀なデバッガー(node-inspector)を使いたい人はnode.js v6を使い続けたほうが良いかも

Last updated at Posted at 2017-09-14

node-inspectorとは?

GitHub ⇨ https://github.com/node-inspector/node-inspector

Node Inspector is a debugger interface for Node.js applications that uses the Blink Developer Tools (formerly WebKit Web Inspector).

JSのデバックをChromeを用いてGUI上でできるモジュール。(嬉しい。泣)
Node.jsとnpmが必要。

ぶち当たった壁

最近Node.jsをいじり始めて、「デバッガーがほしい...console.log()はもう嫌だ...」となっていました。
そこで出会ったのがnode-inspector。CUIじゃなくてGUIでできる部分もフレンドリーで良い。(甘え)

早速インストールしてみる

terminal
$ sudo npm i -g node-inspector

使ってみる...あれ。

terminal
$ $ node-inspector
module.js:491
    throw err;
    ^

Error: Cannot find module '_debugger'
    at Function.Module._resolveFilename (module.js:489:15)
    at Function.Module._load (module.js:439:25)
    at Module.require (module.js:517:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/userName/.nodebrew/node/v8.4.0/lib/node_modules/node-inspector/lib/debugger.js:2:16)
    at Module._compile (module.js:573:30)
    at Object.Module._extensions..js (module.js:584:10)
    at Module.load (module.js:507:32)
    at tryModuleLoad (module.js:470:12)
    at Function.Module._load (module.js:462:3)

なぜだ...出落ちした...

色々調べてみた結果、見つけたのがこちらのページ ⇨ https://github.com/angular/protractor/issues/4307

_debugger and the legacy CLI debugger were removed in Node 8: nodejs/node@90476ac

Oh...どうやらNode.jsのv8では_debuggerとlegacy CLI debuggerが削除されているみたい。
これが問題のよう。

With Node v8 set to enter LTS in October, maybe we could get an update?
https://github.com/nodejs/LTS#lts-schedule1

10月にv8がLTSとなるから、そのタイミングでnode-inspectorもアップデートする感じかい?みたいなことを言っている。
ここを読んでいて、そもそもLTSとはなんぞや?となってしまったので調べた。

node.jsのバージョン管理の話

まず最初にLTSについて。Long-term Supportの略だそう。長期に渡って運用保守が保証されているバージョンのこと。業務などで用いる場合はこちらが無難ですね。
もう一つのバージョンの種類に、"Current"というのがある。こちらは長期に渡る運用保守が保証されておらず、その代わりバンバン機能を追加していくよ〜という立ち位置。

現在のバージョン管理の予定としては、以下のようになっている。
(出典:https://github.com/nodejs/LTS#lts-schedule1)
schedule.png

こんなにきれいにバージョン管理をしているのは素晴らしい...頭が上がりませんね。

結論

結論、node-inspectorを使いたいのであれば、Node.js v6を使うのがよい。
nodebrewを使えば、簡単にNode.jsの複数バージョン管理・切り替えができる。

早速v6をインストールしてみる。
このページを参考に、LTSとしてサポートされているバージョンを確認。⇨ https://nodejs.org/en/
(2017/9/05現在、LTSはv6.11.3で、Currentはv8.5.0)

terminal
//v6.11.3をインストール
$ nodebrew install-binary v6.11.3
Fetching: https://nodejs.org/dist/v6.11.3/node-v6.11.3-darwin-x64.tar.gz
######################################################################## 100.0%
Installed successfully

//しっかりインストールされているか確認
$ nodebrew ls
v6.11.3
v8.4.0

//使用するバージョンを切り替える
$ nodebrew use v6.11.3
use v6.11.3

//切り替わっているか確認
$ nodebrew ls
v6.11.3
v8.4.0

current: v6.11.3

//一度node-inspectorをアンインストール
$ sudo npm uninstall -g node-inspector

//再度インストール
$ sudo npm install -g node-inspector

//node-inspectorが使えるか確認
$ node-inspector                      
Node Inspector v1.1.1
Visit http://127.0.0.1:8080/?port=5858 to start debugging.

//できた!!!!                                                 

今後はしっかりとnode-inspectorの恩恵に預かりつつ、Node.jsを学んでいきたい。

6
6
3

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
6
6