-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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] TypeError: Cannot read properties of undefined (reading '__currentWindow') #3554
Comments
Please provide a minimal repro. |
Hello! I was able to narrow down the problem. It comes from the |
Just like @amrbashir but a bit better :) function App() {
const [appDir, setAppDir] = useState<string | null>(null);
useEffect(() => {
path.appDir().then(dir => setAppDir(dir));
}, [])
return (
<div className="App">
<header className="App-header">
<div className="inline-logo">
<img src={tauriCircles} className="App-logo rotate" alt="logo" />
<img src={tauriWord} className="App-logo smaller" alt="logo" />
</div>
<h1>App Directory</h1>
<p>{appDir !== null ? appDir : 'loading...'}</p>
</header>
</div>
)
} |
Unfortunately changing the code like you did didn't solve the issue for me. |
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
useEffect(() => {
if (window.__TAURI__) {
path.appDir().then(dir => {
console.log('dir', dir);
setAppDir(dir);
});
}
}, []); run the app, open it in the brwoser and check the console log |
I believe the issue is: tauri/tooling/api/src/window.ts Line 1160 in b10a7cf
Solution: dynamic import 🤔? something like: if (window.__TAURI__){
const { path } = await import('@tauri-apps/api')
} or maybe just refactor |
Sorry my issue was not precise enough. I need to be able to run the app in both Tauri and web version. |
And as @marc2332 suggested, dynamic import fix the issue.
|
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 |
We'll help you here #3572 |
Describe the bug
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.Reproduction
No response
Expected behavior
No response
Platform and versions
Stack trace
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: