@tauri-apps/api@1.2.0, "__TAURI_METADATA__" in window cause ReferenceError: window is not defined
linonetwo opened this issue · comments
tauri/tooling/api/src/window.ts
Line 2033 in 50576a5
When running headless tests, this might be troublesome.
Should check typeof window !== 'undefined'
first.
And there will be Cannot use 'in' operator to search for '__TAURI_METADATA__' in undefined
if I manually set global.window = undefined
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:
...b;"__TAURI_METADATA__"in window?b=new s(window.__TAURI_METADATA__.__currentWindow.label,{skip:!0}):(console.warn(`Could not find "window.__TAURI_METADATA__". The "appWindow" value will reference the "main" window label.```
Then it gives a window is not defined:
ReferenceError: window is not defined
at file:///Users/owen/Projects/yark/yark-pages/node_modules/@tauri-apps/api/chunk-QSWLDHGO.js:1:9678
Still having this issue, here's a complete log if it helps: https://pastebin.com/B2qyqrNc
The same is also happening here
@Owez @tauri-apps/api
does not work with Node.js. With SvelteKit, you should to use adapter-static
with the fallback
option and set ssr = false
@Owez
@tauri-apps/api
does not work with Node.js. With SvelteKit, you should to useadapter-static
with thefallback
option and setssr = false
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 if(browser)
as well. For some reason this happens using the static adapter and ssr = false
. The issue could be caused by vite trying to run it as node for whatever reason, and then tauri's injected window being ran?
ssr = false
disables dev SSR. Either way, let's not discuss framework specifics in this issue
Same here in NextJs. Even wrapping components in dynamic
doesn't solve the issue, I need to import any @tauri-apps
with await import
inside the client code completely. Even if that workaround works, it's pretty tedious to use.
ssr = false
disables dev SSR. Either way, let's not discuss framework specifics in this issue
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