-
-
Notifications
You must be signed in to change notification settings - Fork 304
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
templ generate --watch --cmd="go run ." tries to create _templ.txt files in gopath modules #1093
Comments
playing with the watch-pattern cli arg, scoping just to the directory in question, was not able to prevent the error. might be doing something wrong however |
@wsor4035 upon initial inspection, I think we will need a minimal reproduction if possible. This seems like it's something todo with your setup so that would help us to narrow it down. |
@joerdav https://github.com/wsor4035/templwatchsample let me know if you need more than that |
@wsor4035 - you haven't explained what commands you're running (and where you're running them), any errors you're seeing etc. You can also run I can't really understand why you would run templ generate in the GOPATH, rather than your project's directory. It's hard for me to visualise what the problem is. |
the command being run in question is in the issue title. the exact error is
this error is being pulled from the webpage, since it is caught by the templ error handler USERNAME@SERVER~/templwatchsample$ templ generate -v --watch --cmd="go run ."
(✓) Starting post-generation handler
(✓) Walking directory [ path=/home/USERNAME/templwatchsample devMode=true ]
(✓) Starting event handler
(✓) Processing file [ file=/home/USERNAME/templwatchsample/page.templ ]
(✓) Processing file [ file=/home/USERNAME/templwatchsample/main.go ]
(✓) File updated [ file=/home/USERNAME/templwatchsample/main.go ]
(✓) Watching files
(✓) Processing file [ file=/home/USERNAME/templwatchsample/page_templ.go ]
(✓) File not updated [ file=/home/USERNAME/templwatchsample/page_templ.go ]
(✓) Waiting for context to be cancelled to stop watching files
(✓) Generated code [ file=/home/USERNAME/templwatchsample/page.templ in=929.167µs ]
(✓) File updated [ file=/home/USERNAME/templwatchsample/page.templ ]
(✓) Executing command [ command=go run . ]
(✓) Processing file [ file=/home/USERNAME/templwatchsample/page_templ.go ]
(✓) File not updated [ file=/home/USERNAME/templwatchsample/page_templ.go ]
(✓) Processing file [ file=/home/USERNAME/templwatchsample/page_templ.txt ]
(✓) File not updated [ file=/home/USERNAME/templwatchsample/page_templ.txt ]
(✓) Processing file [ file=/home/USERNAME/templwatchsample/page_templ.txt ]
(✓) File not updated [ file=/home/USERNAME/templwatchsample/page_templ.txt ]
(✓) First post-generation event received, starting proxy
(✓) No proxy URL specified, not starting proxy
Listening on :3420
im not running the command in gopath, im running it from the project and somehow templ is trying to write files in the gopath module of its own accord which doesnt make much sense, hence the issue. as stated in the original issue, this doesnt occur if i run happy to provide further information/answer any questions as needed |
Thanks. I think I understand the issue. It looks like a library that you're importing uses templ, and when it sees that watch mode is enabled, the templ code attempts to write to the location next to it. I think I'll need to update templ to be able to distinguish which package is being ran in watch mode, and/or move watch files to a tmp directory or user directory instead, which a few people have already suggested for other reasons. Sorry about that! |
i assume that might take some time to fix/improve/etc? (doesnt appear to be a simple fix i could contribute, and seems you might have architectural ideas on it) i assume for the meantime i should just use note: go workspaces also allow getting around this, but then you lose all versions of dependencies very quickly |
I think this PR should fix it: #1099 Care to give it a try out? |
testing with |
This is a runtime change, you'd have to install the latest version of the templ library as well as use the latest CLI. You should have seen a warning about a version mismatch when you ran templ generate. |
so ran |
Describe the bug
basically what it says in the title, this fails as far as i can tell due to gopath only being read and execute permissions, not write. see golang/go#27161 and golang/go#31481 while i could edit the directory permissions to allow this, that feels suboptimal. not sure why temp needs to cache templ code in gopath modules? (even go workspaces modules would be outside of gopath)
running templ generate and then go run . works fine
To Reproduce
can make one if needed
Expected behavior
code to run and not throw error (which i had to discover via error handler rather than cli error)
the documentation says
which obviously is not the case as gopath is outside the project
Screenshots
If applicable, add screenshots or screen captures to help explain your problem.
Logs
If the issue is related to IDE support, run through the LSP troubleshooting section at https://templ.guide/commands-and-tools/ide-support/#troubleshooting-1 and include logs from templ
templ info
output(✓) os [ goos=linux goarch=amd64 ]
(✓) go [ location=/usr/local/go/bin/go version=go version go1.24.0 linux/amd64 ]
(✓) gopls [ location=/home/REDACTED/go/bin/gopls version=golang.org/x/tools/gopls v0.18.0 ]
(✓) templ [ location=/home/REDACTED/go/bin/templ version=v0.3.833 ]
Desktop (please complete the following information):
gopls
version: golang.org/x/tools/gopls v0.18.0Additional context
N/A
The text was updated successfully, but these errors were encountered: