Closed AlienRecall closed 2 years ago
I literally fixed a bug in the last 10 mins that I think will address this. Please try latest beta using wails update -pre
. A react template would be fantastic!
I'm on v2.0.0-beta.19
Ah I see you're using the latest. Please try removing the "frontend:dev" part of your wails.json and let me know.
%PROJECTPATH%/frontend/build
might be the issue
I replaced the full path with %PROJECTPATH% manually to clear the full issue, by the way I've tried removing frontend:dev from wails.json and I get the same issue with both dev command and built application
I probably should say the idea of the dev server is experimental. People are keen for an external server but there's things to work out yet.
If you generate a project and just use wails dev with the assetdir set, does that work? Dies a standard build work?
Also, sorry, I have no idea about react. If you can get your project to build using npm run build and update assetdir to point to your compiled assets, it absolutely should work š
I remember that on v1 it was working with this settings in project.json
Also on the old v2 updates the settings was
So I've tried to do the same on this version, will try my best to get it working, but I'm not an expert into frontend development
Hi, I've tried to go deep into this error and done some debug on the wails source by adding fmt.Println(path)
on line 72 in internal/frontend/assetserver/assetserver_desktop.go
and seems like wails is searching the index.html
file in the frontend/src
folder instead the frontend/build
as I said in the assetdir
param in wails.json. Can you help me on this?
Yes, absolutely. The default svelte template has this distinction so does that work as expected for you?
It should enter in the build folder instead src, how can i make it enter in the build folder?
Is your project online?
I've also noticed that every time I run wails build it creates the wailsjs
folder outside the /frontend folder, this not happens with wails dev (maybe could be why is crashes)
Is your project online?
No, it's not online, but I can create a repo if you want
I've created the repo and invited you @leaanthony
Hard to help without it
I get 404
try now
You didn't check in your build directory. I'll have to check it tomorrow.
I'm sorry I don't understand what you mean, what I was supposed to do with the build directory?
fwiw i'm having the same issue
@AlienRecall make sure you not only update the settings in the wails.json but also the embed go path in your main.go file. eg:
//go:embed frontend/build
var assets embed.FS
If you point it to the right spot, you should get a window.
however @leaanthony , even if i do this, and I get a window it dies immediately, with something like
TypeError: undfined is not an object (evaluating 'windows.wails._.Init')
which seems to be stemming from the wails/runtime js library
My react App code looks like the following
import React from 'react';
import ReactDOM from 'react-dom';
import 'core-js/stable';
import './index.css';
import App from './App';
import * as serviceWorker from './serviceWorker';
import "bootstrap/dist/css/bootstrap.min.css"
// import './bootstrap.min.css'
import * as Wails from '@wailsapp/runtime';
Wails.Init(() => {
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById("app")
);
});
// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: https://bit.ly/CRA-PWA
serviceWorker.unregister();
@AlienRecall make sure you not only update the settings in the wails.json but also the embed go path in your main.go file. eg:
//go:embed frontend/build var assets embed.FS
If you point it to the right spot, you should get a window.
however @leaanthony , even if i do this, and I get a window it dies immediately, with something like
TypeError: undfined is not an object (evaluating 'windows.wails._.Init')
which seems to be stemming from the wails/runtime js libraryMy react App code looks like the following
import React from 'react'; import ReactDOM from 'react-dom'; import 'core-js/stable'; import './index.css'; import App from './App'; import * as serviceWorker from './serviceWorker'; import "bootstrap/dist/css/bootstrap.min.css" // import './bootstrap.min.css' import * as Wails from '@wailsapp/runtime'; Wails.Init(() => { ReactDOM.render( <React.StrictMode> <App /> </React.StrictMode>, document.getElementById("app") ); }); // If you want your app to work offline and load faster, you can change // unregister() to register() below. Note this comes with some pitfalls. // Learn more about service workers: https://bit.ly/CRA-PWA serviceWorker.unregister();
This solved my issue, really thanks The app is executing normally
@leaanthony changing //go:embed frontend/src
to //go:embed frontend/build
solved my issue, frontend and backend seems communicating perfectly, will push and example to our repo so you can retrieve a template from it
@AlienRecall make sure you not only update the settings in the wails.json but also the embed go path in your main.go file. eg:
//go:embed frontend/build var assets embed.FS
If you point it to the right spot, you should get a window.
however @leaanthony , even if i do this, and I get a window it dies immediately, with something like
TypeError: undfined is not an object (evaluating 'windows.wails._.Init')
which seems to be stemming from the wails/runtime js libraryMy react App code looks like the following
import React from 'react'; import ReactDOM from 'react-dom'; import 'core-js/stable'; import './index.css'; import App from './App'; import * as serviceWorker from './serviceWorker'; import "bootstrap/dist/css/bootstrap.min.css" // import './bootstrap.min.css' import * as Wails from '@wailsapp/runtime'; Wails.Init(() => { ReactDOM.render( <React.StrictMode> <App /> </React.StrictMode>, document.getElementById("app") ); }); // If you want your app to work offline and load faster, you can change // unregister() to register() below. Note this comes with some pitfalls. // Learn more about service workers: https://bit.ly/CRA-PWA serviceWorker.unregister();
Just remove the Wails.Init
function, you do not need it on Wails 2.0
This is my index.js
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
);
// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
I dont understand how that would work, how does your react app get access to the wails runtime?
I read the section on injecting scripts, I guess wails dev
does that for us?
It sounds like you're trying to compile a v1 project in v2. There's no need to wrap your code in Init()
. The migration guide is here: https://wails.io/docs/guides/migrating - I can see that there's no mention of removing that wrapping code so I'll look to fix that. If you find any other gaps in the migration guide, please add it to this ticket.
I dont understand how that would work, how does your react app get access to the wails runtime? I read the section on injecting scripts, I guess
wails dev
does that for us?
@KoduIsGreat The runtime is available to your code on window.runtime
. It's there before your code runs. If you're a typescript person, have a look at the code that's generated in wailsjs/runtime
š
@leaanthony changing
//go:embed frontend/src
to//go:embed frontend/build
solved my issue, frontend and backend seems communicating perfectly, will push and example to our repo so you can retrieve a template from it
@AlienRecall - That's amazing! We need a react template! Couple of things:
@leaanthony changing
//go:embed frontend/src
to//go:embed frontend/build
solved my issue, frontend and backend seems communicating perfectly, will push and example to our repo so you can retrieve a template from it@AlienRecall - That's amazing! We need a react template! Couple of things:
- Would you be interesting in writing a "How to write a template" guide? It can just be bullet points, but would be an amazing contribution to the community
- Are there any gaps in existing documentation that hindered the process of creating the template?
- Finally: It would be amazing to get the template working with the experimental "devserverurl" config. If you are keen to get this working, we can continue on the discussions board and I'll do everything I can to get it working (This scenario is in demand!)
Pushed the template on my repo if you can take a look. Do you want a guide like:
I'm sorry but I'm not so expert at it
Is there a guide on how to setup properly the wails events? I can't get it working, I'm only getting
TypeError: window.wails.EventsOn is not a function. (In 'window.wails.EventsOn("testEvent",function(e){c(e)})', 'window.wails.EventsOn' is undefined)
Where did you read that events are accessed like that? Maybe the docs aren't clear? https://wails.io/docs/reference/runtime/intro
for frontend: window.runtime.EventsOn()
@AlienRecall genuinely curious if the docs weren't clear enough. Docs need love too!
@AlienRecall genuinely curious if the docs weren't clear enough. Docs need love too!
My bad, I directly jumped to the Events page without reading the Introduction. Also GoLand was suggesting me wails.EventsOn so I was thinking it was the right way. I'll be more careful next time
Where did you read that events are accessed like that? Maybe the docs aren't clear? https://wails.io/docs/reference/runtime/intro for frontend:
window.runtime.EventsOn()
fwiw I find code examples to be easier to digest then API documentation at least in the case of API changes
@leaanthony I'd like to get some clarification (and potentially offer some feedback)
In the above discussion we both got our apps working (I think) based on the minified directory aka frontend/build
eg:
wails.json
"assetdir": "frontend/build",
"frontend:build": "npm run build",
"frontend:install": "npm install",
"frontend:dev": "",
main.go
//go:embed frontend/build
var assets embed.FS
In my case, this project was bootstraped via create-react-app.
My application works however, using wails dev, javascript code changes in frontend/src do not cause the dev server to update because the above config is pointing at the output of our npm run build, that is to say its watching for changes in the minified dir and not the src dir.
we also cant watch the frontend/src
directory because wails is looking for an index.html at the root of whatever the asset directory provided, and at least for CRA the index is located at frontend/src/public/index.html
.
I've seen mention of vite, in other discussions and issues, I was considering trying that because vite has some diifferences that might allow me to work around this issue. if there is a react template I think it should be setup so that it uses whatever tools necessary to provide the same developer experience as the other templates have.
What do you think?
Agree. The ideal scenario is using the framework provided dev experience. There's a "devserverurl" option which is a step towards that. The trick is injecting the bindings and runtime. If you look at the wailsjs
dir, there's some "dev" versions of the scripts. The intent there is to allow someone to compile in the scripts. Let me know if you're keen on picking this up. I am.
I see, thats what i figured, and what i tried intiially but my react dev server could never propertly inject the bindings. I tried a few things but maybe i was looking at the wrong things.
If perhaps you can give me a specific example I can try again I'd be happy to help.
@KoduIsGreat I have the same issue with react app - there is no injections of wails scripts into the app. "runtime", "go" are not available on window object.
@KoduIsGreat I finally made it work.
So my recipe for React App CRA:
./frontend/build
//go:embed frontend/build
yarn build
This way running wails dev
we firstly build frontend, then wails inject its scripts.
If your frontend/build folder is empty, it can cause error - wails will complain that it doesn't have embeddable files, just run yarn build
in frontend folder, then cd ../ && wails dev
***Using typescript in react app I declare window and runtime as:
//imports
declare const window: any;
declare const runtime: any;
//use these variables
You can always opens browser to localhost:34115 see the scripts injected in the head of index.HTML then have them in your react HTML š
Description I really don't know if this is a bug or simply wails does not supports react
To Reproduce Steps to reproduce the behaviour:
frontend build
as assetdir in wails.jsonnpm install
as frontend:installnpm run build
as frontend:dev/frontend:buildwails dev
and wait orwails build
an open the applicationExpected behaviour A correct opening of the application
Screenshots If applicable, add screenshots to help explain your problem.
System Details (running wails doctor) System
OS: MacOS Version: 11.6 ID: 199506 Go Version: go1.17.2 Platform: darwin Architecture: amd64
Additional context This is what I get when running
wails dev
(I see the same error when starting the application afterwails build
Thanks in advance for your help, I really appreciate your work and love this project. I'll surely make a react template after this issue has been solved