Open morpig opened 1 year ago
well i'm stupid. there are business logic following, one of which is
const fetch = await fetch(``).....
but bun seems to be blaming the above lines. why?
Could you share as much code as you can so we can try to make the error message better?
async function a(sampling, random, math) {
console.log(Math.random())
const fetch = await fetch('https://google.com')
}
a()
error shown:
0.9973894943346983
1 | async function a(sampling, random, math) {
2 | console.log(Math.random())
^
ReferenceError: Cannot access uninitialized variable.
async function a(sampling, random, math) { console.log(Math.random()) const fetch = await fetch('https://google.com') } a()
error shown:
0.9973894943346983 1 | async function a(sampling, random, math) { 2 | console.log(Math.random()) ^ ReferenceError: Cannot access uninitialized variable.
This is not a bun issue. The problem in your code is that you are trying to redeclare fetch
function as a constant. Thus saying, you can not reassign fetch
to a fetch
. Just use another constant name, like:
const fetchSomePage = await fetch('https://google.com')
As I said above, its my fault for not checking the fetch function.
Why? because Bun is blaming the console.log instead. Line tracing also points at the consolelog line.
As I said above, its my fault for not checking the fetch function.
Why? because Bun is blaming the console.log instead. Line tracing also points at the consolelog line.
Aha. I see your point now. Tried same code in nodejs, and it gives much cleaner error message:
(node:3148) UnhandledPromiseRejectionWarning: ReferenceError: Cannot access 'fetch' before initialization
pointing our directly to the problematic part.
There were two issues here:
1) Bun is pointing to the wrong source line. ~This was fixed in #11581~. Turns out it's a JavaScriptCore bug.
2) JavaScriptCore's ReferenceError
lacks the variable name, which was fixed for Bun in https://github.com/oven-sh/WebKit/pull/56
This should be noticably better in Bun 1.1.13!
What version of Bun is running?
1.0.7+b0393fba6200d8573f3433fb0af258a0e33ac157
What platform is your computer?
Darwin 22.5.0 arm64 arm
What steps can reproduce the bug?
What is the expected behavior?
no errors
What do you see instead?
Additional information
No response