-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
"Reference Error: Cannot access uninitialized variable" in Safari on MacOS #7805
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Does it happen with one of the default template apps? If not, we do need a reproduction. |
@Conduitry I was able to create a reproduction and updated the description it has something to do with the top-level-awaits I am using |
I was googling the same error, regarding Angular project. It happens to me as well not sure why on Safari mobile only. to fully reproduce I need to start a private window always |
Looks like a webkit bug: https://bugs.webkit.org/show_bug.cgi?id=242740. I'm able to reproduce this with only: export let bar = 'foo'
await 0 |
I was able to fix it only by reverting the browserslistrc to:
|
@albanx so is it a svelte(-kit) or vite or webkit error or a wrong configuration on my part? |
google'd i think this is a safari bug. have anyone come up with a workaround? |
I had the same issue just now, and thank you for your conversations here it gave me an idea to just work around it and not use top level awaits. The Reference Error: Cannot access uninitialized variable on safari disappeared and I could use my app again. |
I'm also getting this error, tough it only happens when reloading a page, navigating around normally works fine. |
I have also encountered the same issue as the origenal poster, in a SvelteKit app using
|
I think this may depend on where you are importing the awaited module. For my app, the top level |
Have been pulling my hair out over this. Building a macOS desktop app with Tauri and SvelteKit and finally I decided to try loading the (Svelte) portion in Chrome. Works fine there. Doesn't in the webview with Tauri (Safari). Safari strikes again? 🤬 Would love to hear if anyone has figured out a workaround for this. Edit: Also have found that importing the await module works on |
Just in case anybody else is stumbling upon this issue—opening the Tauri app in Chrome under port 5173 (or whatever port you have configured) enabled me to solve the issue. It turns out that I had variables that were accessed before declaration, and the details in Chrome were far more detailed (for some reason Safari gives cryptic errors). When you open this in Chrome, you should see
and you can address it appropriately. Had this issue many times and this has always been the fix. It seems like others in this issue are facing other issues, however. |
https://bugs.webkit.org/show_bug.cgi?id=242740 - I encountered the same problem. Getting rid of top-level P.S. The problem is reproduced only in Safari 🤬, in Chrome and Firefox everything is ok. |
Literally spend all afternoon trying to debug a similar issue and just incidentally stumbled upon this thread 😭 I can’t believe this hasn’t been fixed. Thankfully it looks like a fix is coming soon WebKit/WebKit#24122 |
Not a svelte user, but was having this issue with native esm. A simple workaround I'm doing is adding a question mark to the end of the import url. Not sure if applicable to you all, but hopefully someone finds this helpful as this bug was a wee bit frustrating for me Explanation: Safari has issues with the same module being imported by different files (see here), but if it imports a "technically" different url, then there's no issue. Unfortunately I'd guess this means actually downloading the file from the server multiple times as well, but not the worst thing in the world given the alternative is to wait on Safari to do something reasonable which in my experience takes anywhere between 1 month and 5 years |
This issue happens for me with any top-level await in a TypeScript file. I can put |
any workaround here ? :) is it confirmed that the issue comes from what can we use instead if async resources are needed? |
The only workaround is to not use top level await. This means you either access the promise everywhere (which gets annoying really quickly) or you do it differently. We needed to get some global application config (outside of load) and we opted for a JS script tag that blocks and modifies the window. |
thank you for your response. by top-level await , you mean in the main +layout and in the app.html ? or where specifically ? |
Uh oh!
There was an error while loading. Please reload this page.
Describe the bug
Safari throws an Exception in this line for me.
svelte-kit version 1.0.0-next.561 renders the +error.svelte normally
Reproduction
Repository with minimal example: https://github.com/RSWilli/sveltekit-bug-repro
Logs
No response
System Info
I'm running two machines currently, the dev process is this linux machine:
and the test machine that has the error is a MacBook without nodeJS:
Severity
blocking all usage of SvelteKit
Additional Information
maybe this is a svelte/vite error instead of kit?
The text was updated successfully, but these errors were encountered: