#1049·templ

templ generate fails on a large file

Author: diyor28Created Jan 17, 2025Updated Jul 24, 2026

Describe the Bug

The templ generate command fails to generate .go code for a large file, citing syntax errors. However, when the file is divided into smaller parts, the generation works without any issues.

To Reproduce

Steps to reproduce the behavior:

  1. Run templ generate on the following file: Gist Link
  2. Observe the error output.

Expected Behavior

The .go code should be generated successfully without errors, even for large files.

Screenshots

Error Screenshot

Logs

templ generate
(✗) Error [ error=failed to generate code for "/Users/diyorkhaydarov/Projects/sdk/icons/icons.templ": /Users/diyorkhaydarov/Projects/sdk/icons/icons.templ parsing error: templ: malformed templ expression, expected `templ functionName() {`: line 20, col 0 ]
(✗) Command failed: generation completed with 1 errors

templ info Output

(✓) os [ goos=darwin goarch=arm64 ]
(✓) go [ location=/opt/homebrew/bin/go version=go version go1.23.2 darwin/arm64 ]
(✓) gopls [ location=/Users/diyorkhaydarov/go/bin/gopls version=golang.org/x/tools/gopls v0.17.1 ]
(✓) templ [ location=/Users/diyorkhaydarov/go/bin/templ version=v0.3.819 ]