oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.18k stars 2.77k forks source link

Bun Inspect ignoring debugger statement #4842

Open Braayy opened 1 year ago

Braayy commented 1 year ago

What version of Bun is running?

1.0.0+822a00c4d508b54f650933a73ca5f4a3af9a7983

What platform is your computer?

Linux 6.1.52-1-lts x86_64 unknown

What steps can reproduce the bug?

I've search about debugging with bun, and i found out about the --inspect flag.

So i've got testing this feature with a simple script, but it didn't work out.

Running bun --inspect index.ts simply logs "Hello World!" and nothing else happens. The debugger statement is ignored.

debugger;
const message = 'Hello World!';
console.log(message);

So i thought that i needed an infinite loop at the end for it to work.

debugger;
const message = 'Hello World!';
console.log(message);
while (true) {}

The code is executed normally and hangs at the end, but now a web debugger link appears on the console as well.

So i click on the link to access the web debugger, but it is empty. No breakpoint hit neither source code for me to inspect.

image

So then i tested if a get something if a do a infinite loop using setInterval.

setInterval(() => {
  debugger;
  console.log('Hello World!');
}, 1000);

And now it works correctly, even if i put the debugger statement.

image

What is the expected behavior?

I think the expected behavior is that if there is a debugger statement, even if the program doesn't hang with a infinite loop, a breakpoint hit should make the program stop, a web debugger link should appear on the console and the web debugger should be populated with the running script.

What do you see instead?

No response

Additional information

No response

telamon commented 10 months ago

Confirming that debugger statements are ignored. Please fix this :pray:

bnwa commented 1 month ago

Also encountering this behavior in very simple graph walk file logic, should have multiple opportunities to break on the keyword

aureliomarcoag commented 4 weeks ago

I could work around this by using

bun run --inspect-brk <file>

which adds and breaks at the first line of the file.

From here, I just open the inspect URL in a browser and hit Continue script execution (⌃Y or ⌃\) and then bun correctly breaks at the debugger I added to my code.

tmewett commented 1 week ago

Is there any other way to pause the Bun debugger via code? Any Bun-specific API or something?