確認した環境
visual studio code: 1.39.2
babel-node: 7.2.2
launch.jsonを開く
画面右端からデバッグアイコンをクリックし、デバッグの設定アイコンをクリック、プルダウンリストから「Node.js」を選択すると、デフォルトのlaunch.jsonが表示されます。
デフォルトのlaunch.json
{
// IntelliSense を使用して利用可能な属性を学べます。
// 既存の属性の説明をホバーして表示します。
// 詳細情報は次を確認してください: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "プログラムの起動",
"program": "${file}"
}
]
}
launch.jsonを編集
launch.jsonに以下のように編集します。※メインのjsがindex.js
である前提です。異なる場合は、"program"の値を書き換えてください。
{
// IntelliSense を使用して利用可能な属性を学べます。
// 既存の属性の説明をホバーして表示します。
// 詳細情報は次を確認してください: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "babel-nodeのデバッグ",
"program": "${workspaceFolder}/index.js",
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/babel-node",
}
]
}
デバッグの実行
画面右端からデバッグアイコンをクリックし、上で編集した設定名("name")が選択されているのを確認し、デバッグの開始アイコンをクリックします。