gohugoio/hugo · error
%s
Error message
%s
What it means
The fallback error formatter used in BuildClient.Build when an esbuild error has a Location but Hugo fails to open or stat the referenced source file. When the file lookup itself errors, the original esbuild message text is returned via fmt.Errorf("%s", errorMessage) without source-context attachment.
Source
Thrown at internal/js/esbuild/build.go:173
contentr = resolvedError.Content
errorPath = resolvedError.Path
errorMessage = resolvedError.Message
}
if contentr != nil {
defer contentr.Close()
}
if err == nil {
fe := herrors.
NewFileErrorFromName(errors.New(errorMessage), errorPath).
UpdatePosition(text.Position{Offset: -1, LineNumber: loc.Line, ColumnNumber: loc.Column}).
UpdateContent(contentr, nil)
return fe
}
return fmt.Errorf("%s", errorMessage)
}
var errors []error
for _, msg := range result.Errors {
errors = append(errors, createErr(msg))
}
// Return 1, log the rest.
for i, err := range errors {
if i > 0 {
c.rs.Logger.Errorf("js.Build failed: %s", err)
}
}
return result, errors[0]
}
View on GitHub (pinned to 52c9bd7908)
Solutions
- Read the message text directly — it is esbuild's original diagnostic.
- Cross-reference the failing import/entry point in your assets to reconstruct context.
- If reproducible, run `hugo --gc` to clear stale state and rebuild.
Defensive patterns
Strategy: try-catch
Try / catch
When Build returns an error, do not assume it carries source-line context; check whether the error implements herrors.FileError before rendering line annotations, and fall back to printing the raw message text.
Prevention
- Treat the message text as authoritative when source context is absent.
- Don't depend on line/column annotations in your error UI for this path.
- Cross-reference the failing import in your assets manually when this fallback fires.
When it happens
Trigger: Esbuild returns a build error referencing a file path; Hugo's attempt to open/stat that path (either on the OS filesystem or the source filesystem) fails with err != nil. The fallback path executes, returning the bare esbuild text without line-anchored content.
Common situations: Errors pointing to generated/virtual files that have no backing on disk; transient file-not-found during server rebuilds; source files in Hugo namespaces that don't map to a real file.
Related errors
- {}
- id must be set
- id must not contain backslashes
- id must not contain forward slashes
- failed to build JS batch %q: %w
AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09).
Data as JSON: /api/errors/538455e1dc7f3358.
Report an issue: GitHub.