bokwoon95/wgo

`undefined: myMethod` using `templ`

Closed this issue · 2 comments

Following the templ documentation I wanted to try wgo to see about the automatic page reloading that air doesn't have. Builtin templ HMR seems quite slow. I am running the command they provided, after installing wgo:

wgo -file=.go -file=.templ -xfile=_templ.go templ generate :: go run appname.go

I have a appname.go file, and adjacent to this, a base.templ file. They both live in the same package main.

When running the above I'm getting the following error:
./appname.go:8:18: undefined: hello (hello is a function in the templ file)

I don't seem to get this error when using templ's built in HMR, or with Air.

Please let me know if this is something on my end I could be doing wrong!

Thanks

Ok um actually wgo doesn't have the automatic page reloading either. It's pretty much identical to air, except wgo doesn't need a config file to run. Automatic page reload is only available through templ and the --proxy flag, which injects JavaScript into the webpage and automatically reloads it when files change.

But regarding the error, go run actually takes in a list of files to compile. go run appname.go compiles only appname.go, so a function defined in another file (even if they're in the same package) would turn up as undefined. You can manually include all files with go run appname.go base_templ.go, but a better way would be to invoke the package directly with go run . (https://stackoverflow.com/a/52721104).

Yikes, dead simple. My bad, appreciate the quick response.