Can someone provide a step-by-step guide on how to effectively debug TypeScript CDK code in Cloud9?
I'm able to set breakpoints by clicking in the gutter (the space left of the line numbers), as described in the "Debug Your Code" documentation.
However, I'm having trouble getting the debugger to pause at the breakpoints when running the cdk deploy command. I've tried the following steps:
- Added the
--inspect-brk
flag to the cdk deploy
command in the cdk.json
file:
"app": "npx ts-node --prefer-ts-exts --inspect-brk bin/aws-genai-llm-chatbot.ts"
However, when I run cdk deploy
, I get the following error:
Error: Unknown or unexpected option: --inspect-brk
It seems like the --inspect-brk
flag is not recognized by the ts-node
command.
- As an alternative, I tried modifying the cdk.json file to use the node command directly with --inspect-brk and specifying the path to the ts-node executable:
"app": "node --inspect-brk ./node_modules/ts-node/dist/bin.js --prefer-ts-exts bin/aws-genai-llm-chatbot.ts"
- Then I set breakpoints in my TypeScript CDK code by clicking on the gutter to the left of the line numbers.
- When I ran the
cdk deploy
command in the terminal, I got the following output:
Debugger listening on ws://127.0.0.1:9229/b000124e-7e73-4d3e-adb7-abf50620df8a
For help, see: https://nodejs.org/en/docs/inspector
So then I opened the debugger window, but didn't see anything in there, as you can see in the screenshot.
I did find a fantastic article on "Debugging TypeScript/JavaScript CDK projects - a few tips and tricks" but it wasn't specific to Cloud9.