kit: "Reference Error: Cannot access uninitialized variable" in Safari on MacOS
Describe the bug
Safari throws an Exception in this line for me.
Reference Error: Cannot access uninitialized variable
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
- SSR needs to be turned off
- a svelte module needs to import a module that uses top-level-await to initialize an exported variable
Logs
No response
System Info
I’m running two machines currently, the dev process is this linux machine:
System:
OS: Linux 5.15 Arch Linux
CPU: (8) x64 Intel(R) Core(TM) i5-8350U CPU @ 1.70GHz
Memory: 20.14 GB / 31.22 GB
Container: Yes
Shell: 5.9 - /bin/zsh
Binaries:
Node: 18.3.0 - ~/.nvm/versions/node/v18.3.0/bin/node
Yarn: 1.22.19 - /usr/bin/yarn
npm: 8.11.0 - ~/.nvm/versions/node/v18.3.0/bin/npm
Browsers:
Chromium: 107.0.5304.110
Firefox: 107.0
npmPackages:
@sveltejs/adapter-static: ^1.0.0-next.21 => 1.0.0-next.48
@sveltejs/kit: ^1.0.0-next.417 => 1.0.0-next.561
svelte: ^3.53.1 => 3.53.1
typescript: ^4.9.3 => 4.9.3
and the test machine that has the error is a MacBook without nodeJS:
macOS 12.5.1
Safari 15.6.1
Severity
blocking all usage of SvelteKit
Additional Information
maybe this is a svelte/vite error instead of kit?
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 4
- Comments: 20 (2 by maintainers)
https://bugs.webkit.org/show_bug.cgi?id=242740 - I encountered the same problem. Getting rid of top-level
awaithelped.P.S. The problem is reproduced only in Safari 🤬, in Chrome and Firefox everything is ok.
thank you for your response.
by top-level await , you mean in the main +layout and in the app.html ? or where specifically ?
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
any workaround here ? 😃
is it confirmed that the issue comes from
awaitinapp.htmlor+layout.svelte?what can we use instead if async resources are needed?
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 https://github.com/WebKit/WebKit/pull/24122
I think this may depend on where you are importing the awaited module. For my app, the top level
+layout.tsis depending on an asynchronous module, so there is no way to get the page to load.I was able to fix it only by reverting the browserslistrc to: