VSCodeバージョン:1.10.2 OSバージョン:Windows 7 Profesionnal、SP1ノードバージョン:6.10.0
皆さんこんにちは。
nodemonで起動するときに、ビジュアルスタジオコードを使用してサーバー側でtypescriptコード(またはjavascriptコード)をデバッグしようとしています。私はlaunch.jsonに次のような新しい構成を追加しました:
{
"type": "node",
"request": "launch",
"name": "Launch server with Nodemon",
"runtimeExecutable": "nodemon",
"runtimeArgs": [
"--debug=5858"
],
"program": "${workspaceRoot}/src/server.ts",
"restart": true,
"port": 5858,
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"outFiles": ["${workspaceRoot}/build/**/*.js"]
}
私は、JavaScriptファイルを適切に構築するtscを実行しているvscodeのタスクを持っています。これは私の現在のタスク設定です:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "tsc",
"isShellCommand": true,
"args": ["-p", "."],
"showOutput": "silent",
"problemMatcher": "$tsc"
}
typescriptファイルを変更すると、JavaScriptファイルが期待どおりに生成されます。また、javascriptファイルが生成されると、nodejsサーバーは期待どおりに再起動します。
しかし、ブレークポイント(typescriptファイルまたはjavascriptファイル)でブレークすることはできません。
それが問題なのか、何か足りないものがあるのか教えていただけますか?
ご協力ありがとうございました
vscodeに問題があるようです(問題はgithub [ここ] [1]で開かれています)。ただし、現時点での回避策は、構成(launch.json)のプロトコルを「inspector」に設定することです。このオプションを使用すると、ブレークポイントに正しく到達するようになりました。
また、「runtimeArgs」オプションの「--debug = 5858」を「--inspect = 5858」に変更します。
{
"type": "node",
"request": "launch",
"name": "Launch server with Nodemon",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/nodemon",
"runtimeArgs": [
"--inspect=5858"
],
"program": "${workspaceRoot}/src/server.ts",
"restart": true,
"port": 5858,
"protocol": "inspector",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"outFiles": ["${workspaceRoot}/build/**/*.js"],
"sourceMaps": true
},
また、その後、次のようなメッセージが点滅するエラーが発生した場合:
ランタイムプロセスに接続できず、10000ミリ秒後にタイムアウトします-(理由:ターゲットに接続できません:接続ECONNREFUSED 127.0.0.1:5858)
これは、プログラムが短すぎて、デバッガーにブレークポイントを中断するのに十分な時間がないことを意味します。これを解決するには、オプション「runtimeArgs」に2番目のランタイム引数「--debug-brk」を追加し、「stopOnEntry」オプションもtrueに設定します。
最終的な構成は次のようになります。
{
"type": "node",
"request": "launch",
"name": "Launch server with Nodemon",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/nodemon",
"runtimeArgs": [
"--inspect=5858",
"--debug-brk"
],
"stopOnEntry": true,
"program": "${workspaceRoot}/src/server.ts",
"restart": true,
"port": 5858,
"protocol": "inspector",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"outFiles": ["${workspaceRoot}/build/**/*.js"],
"sourceMaps": true
}
エントリのjavascriptファイルの最初の行で壊れているはずです。次に、F5キーを押すと、独自のブレークポイントに到達します。
プログラムを実行するたびにF5キーを押したくない場合は、代わりに、少なくとも1000ミリ秒のタイムアウトでメインエントリコードをsetTimeOut関数内に埋め込むことができます。
これらのオプションはすべて、vscodeにブレークポイントを壊すのに十分な時間を与えます。
://github.com/Microsoft/vscode/issues/23900「GitHubの問題」
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加