-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
@tauri-apps/api@1.2.0, "__TAURI_METADATA__" in window cause ReferenceError: window is not defined #6226
Comments
And there will be |
Looks like this is failing my SvelteKit production builds (open image in new window): This spews out a massive JS chunk for SvelteKit. It mentions tauri at the end:
Then it gives a window is not defined:
|
Still having this issue, here's a complete log if it helps: https://pastebin.com/B2qyqrNc |
The same is also happening here |
@Owez |
I'm using both, the code I wrote had problems with vite's dev ssr on sveltekit erroring so everything I've wrote has been protected inside of an |
|
Same here in NextJs. Even wrapping components in |
See #6554 (possible workaround also included) |
For those afflicted by this issue when using rspc with Tauri and NextJS (very specific, I know), I've chucked together a workaround transport that avoids importing Tauri at all during build time and server-side. https://gist.github.com/kaylendog/ea3d2ff8607d8433849c6bd431fb39b0 |
For folks using sveltekit and/or vite, one workaround is to use vite-plugin-iso-import. Before// src/routes/+layout.ts
import { appDataDir } from '@tauri-apps/api/path'
import { appWindow } from '@tauri-apps/api/window'
// ERROR
// [vite] Error when evaluating SSR module /src/routes/+layout.ts: failed to import "@tauri-apps/api/path"
// ReferenceError: navigator is not defined After// src/routes/+layout.ts
import { appDataDir } from '@tauri-apps/api/path?client'
import { appWindow } from '@tauri-apps/api/window?client'
if (!import.meta.env.SSR) {
console.log({ appWindow, appDataDir })
}
// All good, no error To retain full LSP/intellisense functionality, a couple of steps might be required. One of which is the following: // src/lib/types/global.d.ts
declare module '@tauri-apps/api/path?client' {
import all from '@tauri-apps/api/path'
export = all
}
declare module '@tauri-apps/api/window?client' {
import all from '@tauri-apps/api/window'
export = all
} See the docs for setup info. This workaround used to be mentioned in the svelte docs, but seems to have missed the cut in a recent docs refactor. Nevertheless, it remains a viable workaround. |
This was fixed in v2 by removing variables like appWindow and solely relying on functions like getCurrent(). Since this is a breaking change we can't backport it to v1. Until v2 hits stable you'll have to keep using |
Same issue while using 2.0.0-beta. |
@bennekrouf |
tauri/tooling/api/src/window.ts
Line 2033 in 50576a5
When running headless tests, this might be troublesome.
Should check
typeof window !== 'undefined'
first.The text was updated successfully, but these errors were encountered: