Skip to content
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

window.go is undefined when calling Wails backend functions #3991

Closed
hellokaton opened this issue Jan 9, 2025 · 4 comments
Closed

window.go is undefined when calling Wails backend functions #3991

hellokaton opened this issue Jan 9, 2025 · 4 comments
Labels
Bug Something isn't working

Comments

@hellokaton
Copy link

Description

When trying to call Wails backend functions from the frontend, getting error:

App.js:10 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'main')
at Greet (App.js:10:22)
at handleClick (about.lazy.tsx:14:27)

This indicates that window.go object is not properly injected by Wails.

To Reproduce

  1. Start app with wails dev
  2. Navigate to About page
  3. Click the "Click me" button that calls Greet() backend function
  4. Error appears in console

Expected behaviour

  • window.go should be properly injected by Wails
  • Backend functions should be callable from frontend
  • No errors when clicking the button

Screenshots

image image image

Attempted Fixes

No response

System Details

# Wails
Version | v2.9.2

# System
┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
| OS           | MacOS                                                                                                                       |
| Version      | 15.2                                                                                                                        |
| ID           | 24C101                                                                                                                      |
| Go Version   | go1.23.2                                                                                                                    |
| Platform     | darwin                                                                                                                      |
| Architecture | arm64                                                                                                                       |
| CPU          | Apple M1 Pro                                                                                                                |
| GPU          | Chipset Model: Apple M1 Pro Type: GPU Bus: Built-In Total Number of Cores: 14 Vendor: Apple (0x106b) Metal Support: Metal 3 |
| Memory       | 16GB                                                                                                                        |
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

# Dependencies
┌──────────────────────────────────────────────────────────────────────┐
| Dependency                | Package Name | Status    | Version       |
| Xcode command line tools  | N/A          | Installed | 2409          |
| Nodejs                    | N/A          | Installed | 22.10.0       |
| npm                       | N/A          | Installed | 11.0.0        |
| *Xcode                    | N/A          | Installed | 15.4 (15F31d) |
| *upx                      | N/A          | Installed | upx 3.96      |
| *nsis                     | N/A          | Installed | v3.09         |
└────────────────────── * - Optional Dependency ───────────────────────┘

Additional context

  • Already tried importing Wails runtime and checking initialization
  • Backend functions are properly bound in main.go
  • App starts without any obvious errors
  • Need help debugging why Wails runtime is not being injected properly
  • I used @tanstack/react-router
@hellokaton hellokaton added the Bug Something isn't working label Jan 9, 2025
@hellokaton
Copy link
Author

https://wails.io/docs/guides/troubleshooting#when-i-navigate-away-from-indexhtml-i-am-unable-to-call-methods-on-the-frontend

As per the docs I added the injection script but it shows 404 in the network tab, I don't have this problem with the empty project I created using wails init -n wails-react-ts -t react-ts.

image image

@leaanthony
Copy link
Member

Looks like you're connecting to Vite and expecting Go to work, which it won't. You'll need to connect to http://localhost:34115 for Go to work

@hellokaton
Copy link
Author

Thanks for your answer, I found the problem, I should have executed it in the client and not in the browser.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants