-
Notifications
You must be signed in to change notification settings - Fork 53
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
Issue on Safari : Promise Rejection: ReferenceError: Cannot access uninitialized variable. #137
Comments
Is this a bug (or rather, a missing feature) in Svelte? sveltejs/svelte#5501 Libauth uses top-level await to simplify instantiation/management of the WASM crypto implementations. |
Hi @bitjson , thank you for the feedback. Yes I think you might be right. Please excuse the noise :) |
Hi @bitjson, according to this comment ( sveltejs/kit#12406 (comment) ) "Libraries and even SvelteKit need to be refactored to avoid the use of top-level awaits in the browser." What is your take on that please? Is it feasible to load WASM routines in your library without the use of "top-level awaits in the browser" ? |
I realize I'm a bit late to this party, but was experimenting with Svelte(Kit) recently. I was only able to get this working through a bit of trial+error (aided by scattered Google searches). In case it helps anyone in future: For import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vite';
import { nodePolyfills } from 'vite-plugin-node-polyfills';
export default defineConfig({
plugins: [sveltekit(), nodePolyfills({
// This was for the electrum-cash library... unrelated, but copying here in case pertinent as example to others.
include: ['event', 'net', 'tls'],
})],
build: {
target: "es2022"
},
esbuild: {
target: "es2022"
},
// NOTE: This was important! Top-level await would not work without this!
optimizeDeps:{
esbuildOptions: {
target: "es2022",
}
}
}); ... and in const config = {
// ...
viteFinal: async (config) => {
if(!config.build) {
config.build = {};
}
config.build.target = ['esnext'];
return config;
}
// ...
} I think I recall reading that |
Hi @jimtendo , what a nice surprise to see movement on this. I did not get round to trying more things yet, so I'm excited to see if your solution works for me too. Will report back in the next days. Thanks for sharing |
I'm very sorry, I'd actually completely missed that your issue was Safari! I did not test that - but suspect I would've bumped into the same issue you have. Not sure if it's of help to you (I kind of doubt it would work), but there is a Top-Level-Await polyfill I've used on Quasar projects successfully to support old versions of KDE's Falkon browser: https://www.npmjs.com/package/vite-plugin-top-level-await No idea if that would work on your case as it seems that Safari does support Top-Level-Await already (so polyfill probably wouldn't apply itself). |
Hi @jimtendo , not worries at all - thanks for trying to help. If you are curious, I don't need a import { sveltekit } from '@sveltejs/kit/vite'
import { defineConfig, type UserConfigExport } from 'vitest/config'
import browserslistToEsbuild from 'browserslist-to-esbuild'
export default defineConfig({
...,
target: browserslistToEsbuild(),
plugins: [sveltekit()],
optimizeDeps: {
esbuildOptions: {
target: 'esnext',
},
},
build: {
target: 'esnext',
commonjsOptions: {
include: [ ..., /node_modules/ ],
},
},
} as UserConfigExport) |
Hi,
Thank you for the nice library. Sadly, it seems there is an issue on Safari.
Please refer to
The example repository above is to illustrate the problem via a small reproducible example. However, in a rather big code base, libauth is the only dependency which is having issues in Safari, failing with
Promise Rejection: ReferenceError: Cannot access uninitialized variable.
.Therefore I imagine it has to do with how libauth is packaged, and not something intrinsic to vite / sveltekit.
Would appreciate it if you could take a look.
Thanks
The text was updated successfully, but these errors were encountered: