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

bug: "github.com/a-h/templ/runtime" imported as templruntime and not used #834

Closed
farhadhf opened this issue Jul 6, 2024 · 2 comments · Fixed by #841
Closed

bug: "github.com/a-h/templ/runtime" imported as templruntime and not used #834

farhadhf opened this issue Jul 6, 2024 · 2 comments · Fixed by #841
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@farhadhf
Copy link

farhadhf commented Jul 6, 2024

I have a small templ file that only includes scripts, after upgrading to templ v0.2.747 today I'm getting this error:

"github.com/a-h/templ/runtime" imported as templruntime and not used

You can reproduce it by running templ generate on this:

package components

script SetObjectName(name string) {
    window.object_name = name
}
@a-h
Copy link
Owner

a-h commented Jul 8, 2024

Thanks for this.

The solution is to update the generator to add a fake import to the generated code, e.g. var _ = templruntime.GeneratedTemplate that way, even if the code doesn't use the import explicitly, it won't cause this error.

Alternatives involve checking that the imports are used by the generated code, which would add complexity for little benefit.

@a-h a-h added bug Something isn't working good first issue Good for newcomers labels Jul 8, 2024
@joerdav joerdav changed the title "github.com/a-h/templ/runtime" imported as templruntime and not used bug: "github.com/a-h/templ/runtime" imported as templruntime and not used Jul 8, 2024
@joerdav
Copy link
Collaborator

joerdav commented Jul 8, 2024

Agree on the var approach, this will also solve the problem for when someone has no templ code in a templ file.

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

Successfully merging a pull request may close this issue.

3 participants