-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
[bug] SvelteKit SPA window is not defined
on build
#6554
Comments
window is not defined
on buildwindow is not defined
on build
This is the same issue as #6226 |
I figured out a workaround! This bug is preventing me from shipping my Tauri + SvelteKit application, so I came up with this:
let invokeFunction: any = () => console.log('invoking nothing!');
if (!import.meta.env.SSR) {
const { invoke } = await import('@tauri-apps/api');
invokeFunction = invoke;
}
export async function invoke<T>(name: string, args?: any): Promise<T> {
return await invokeFunction(name, args);
} Since the error is probably caused by importing Now for this to work, we need top level await, which is not supported by default (at least it wasn't for me). Luckily, all you need to do is to modify your
export default defineConfig({
//...
build: {
target: 'esnext'
},
//...
}); I did the same thing for a few more tauri functions, but it works in the exact same way. This is very ugly though, especially since you lose type all type information about the functions (unless you want to manually copy and maintain the interfaces from Tauri's source) and I hope this could be fixed someday. |
@cegredev If it's just about |
@FabianLars That works too and is a lot cleaner! Thanks! Does this just work with |
It will work with all modules that don't export variables (only functions and objects), iirc this currently includes the path and window modules (therefore the "root" module you imported |
Good to know, thank you! I'll stick to my solution where there's no other way, then. |
@FabianLars Actually, I think using |
Woah thanks @cegredev :) I didn't get a notification before but this seems to work! |
I've updated my imports to use either:
or
The same issue as seen in #6226 persists in my debug & production build (v1.6.0). |
Describe the bug
Bug report stems from #6226 (see #6226 (comment)). I'm trying to use Tauri with SvelteKit using an SPA, but I'm having troubles trying to deploy it.
When I run
npm run build
ornpm run tauri build
, the SvelteKit app errors out in the build process during thevite build
packaging because of the@tauri-apps/api
package including the following check (formatted code, its normally in a single line bundle):This errors out with the following:
I have SvelteKit SPA set up correctly with
adapter-static
andexport const ssr = false
in my root+layout.ts
. It seems to be an issue with Vite always wanting to run SSR no matter what's been configured, so for now guarding Tauri is the only real solution.Reproduction
@tauri-apps/api
somewhere (im using it for FS open file/folder)Expected behavior
It should build a working Tauri bundle.
Platform and versions
Stack trace
Additional context
No response
The text was updated successfully, but these errors were encountered: