gohugoio/hugo · error

pageOutput is nil for output idx %d

Error message

pageOutput is nil for output idx %d

What it means

Panic in shiftToOutputFormat: after setting ps.pageOutputIdx = idx, the looked-up ps.pageOutputs[idx] is nil. This means the page's output-format slots contain a nil at the requested index, signalling that the page outputs array was built incompletely or the index is out of sync with available outputs.

Source

Thrown at hugolib/page.go:886

	return ps.posFromInput(ps.m.content.mustSource(), offset)
}

// shiftToOutputFormat is serialized. The output format idx refers to the
// full set of output formats for all sites.
// This is serialized.
func (ps *pageState) shiftToOutputFormat(isRenderingSite bool, idx int) error {
	if err := ps.initPage(); err != nil {
		return err
	}

	if len(ps.pageOutputs) == 1 {
		idx = 0
	}

	ps.pageOutputIdx = idx
	ps.pageOutput = ps.pageOutputs[idx]
	if ps.pageOutput == nil {
		panic(fmt.Sprintf("pageOutput is nil for output idx %d", idx))
	}

	// Reset any built paginator. This will trigger when re-rendering pages in
	// server mode.
	if isRenderingSite && ps.pageOutput.paginator != nil && ps.pageOutput.paginator.current != nil {
		ps.pageOutput.paginator.reset()
	}

	if isRenderingSite {
		cp := ps.pageOutput.pco
		if cp == nil && ps.canReusePageOutputContent() {
			// Look for content to reuse.
			for i := range ps.pageOutputs {
				if i == idx {
					continue
				}
				po := ps.pageOutputs[i]

View on GitHub (pinned to 52c9bd7908)

Solutions

  1. Clean-rebuild to discard stale per-page output state.
  2. Review [outputs] configuration per page kind and language; remove unused/gap-inducing formats.
  3. Upgrade Hugo; report the idx value and page path if it reproduces.

Example fix

# before: outputs config leaves an empty slot mid-slice
[outputs]
home = ['html']
page = ['html', '', 'rss']

# after: contiguous valid formats only
[outputs]
home = ['html','rss']
page = ['html','rss']
Defensive patterns

Strategy: validation

Validate before calling

// Keep [outputs] contiguous and valid per kind/language; clean-rebuild to discard stale slots.
// hugo.toml example:
//   [outputs]
//   home = ['html','rss']
//   page = ['html']

Try / catch

// Wrap Build in recover() to surface the failing idx cleanly (see 781).

Prevention

When it happens

Trigger: Rendering a page for output index idx when the pageOutputs slice has a nil at that position. Happens when output formats are configured/filtered such that a slot is allocated but not populated, or when the global output index passed in does not match the page's own outputs.

Common situations: Multi-output/multilingual setups where output-format indexing drifts. A custom output format configuration with gaps. A bug in how the global vs per-page output indices align (often after an outputs config change). Incremental build staleness.

Related errors


AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09). Data as JSON: /api/errors/9d2df9655807b1f2. Report an issue: GitHub.