You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[bug] TypeError: Cannot read properties of undefined (reading '__currentWindow') #3554
Trying to update my app to latest Tauri I get this error TypeError: Cannot read properties of undefined (reading '__currentWindow').
This is all the @tauri-apps/api imports I have in my app:
import { once } from '@tauri-apps/api/event';
import { exit } from '@tauri-apps/api/process';
import type { Child } from '@tauri-apps/api/shell';
import { Command } from '@tauri-apps/api/shell';
import { writeFile, readTextFile, removeFile, readDir, createDir } from '@tauri-apps/api/fs';
I did guard all calls with if ('__TAURI__' in window) { } but it's not enough.
Hello! I was able to narrow down the problem. It comes from the path module.
In this minimal reporduction made with create-tauri-app I call path.appDir(). You can see in the console the error above. https://github.com/Janaka-Steph/tauri-app-path
We're kinda missing the actual problem here. The issue we were initially talking about was that importing X* crashes the frontend in browser even if the function call itself is guarded with if (window.__TAURI__).
with X now being identified as path.appDir() or the path module in general
Change it to:
Sorry my issue was not precise enough. I need to be able to run the app in both Tauri and web version.
I added a guard in this repro in useEffect as @FabianLars sugested.
It works with cargo tauri dev but with yarn start I get the error.
This is a really weird use case lol I thought it was an issue with Tauri itself.
You could move all Tauri API usage to a single file and conditionally import that, I do this at work using Webpack. The easy solution would be changing your HTML file to initialize window.__TAURI_METADATA__ with a dummy value.
Activity
amrbashir commentedon Feb 24, 2022
Please provide a minimal repro.
astral-horizon-labs commentedon Feb 28, 2022
Hello! I was able to narrow down the problem. It comes from the
pathmodule.In this minimal reporduction made with create-tauri-app I call
path.appDir(). You can see in the console the error above.https://github.com/Janaka-Steph/tauri-app-path
amrbashir commentedon Feb 28, 2022
Your minimal repro had wrong usage of async function inside jsx.
your App.tsx should be like this
I am not a good react dev so there might be a better way to do this.

Anyways it works fine with the above snippet.
marc2332 commentedon Feb 28, 2022
Just like @amrbashir but a bit better :)
astral-horizon-labs commentedon Feb 28, 2022
Unfortunately changing the code like you did didn't solve the issue for me.
I am using a MacBook M1, maybe it's related to that.
FabianLars commentedon Feb 28, 2022
We're kinda missing the actual problem here. The issue we were initially talking about was that importing X* crashes the frontend in browser even if the function call itself is guarded with
if (window.__TAURI__).Change it to:
run the app, open it in the brwoser and check the console log
marc2332 commentedon Feb 28, 2022
I believe the issue is:
tauri/tooling/api/src/window.ts
Line 1160 in b10a7cf
Solution: dynamic import 🤔?
something like:
or maybe just refactor
tauri/api/windowto avoid having that module-scoped variableastral-horizon-labs commentedon Feb 28, 2022
Sorry my issue was not precise enough. I need to be able to run the app in both Tauri and web version.
I added a guard in this repro in useEffect as @FabianLars sugested.
It works with
cargo tauri devbut withyarn startI get the error.astral-horizon-labs commentedon Feb 28, 2022
And as @marc2332 suggested, dynamic import fix the issue.
But would be nice if I can keep regular imports.
lucasfernog commentedon Feb 28, 2022
This is a really weird use case lol I thought it was an issue with Tauri itself.
You could move all Tauri API usage to a single file and conditionally import that, I do this at work using Webpack. The easy solution would be changing your HTML file to initialize
window.__TAURI_METADATA__with a dummy value.lucasfernog commentedon Feb 28, 2022
We'll help you here #3572
fix(api): do not throw an exception if __TAURI_METADATA__ is not set, f…