gohugoio/hugo · error
deployment target not found
Error message
deployment target %q not found
What it means
deploy.New (deploy/deploy.go:88) selects the deployment target by name (from the --target flag). If a name is given and no entry in dcfg.Targets (the [[deployment.targets]] list) matches it, Hugo cannot proceed and returns this error. With an empty name it defaults to the first target.
Solutions
- List the [[deployment.targets]] names in your config and correct the --target spelling/whitespace/case.
- Add the missing [[deployment.targets]] entry with the desired name.
- Omit --target to deploy to the first defined target.
- Ensure at least one target is configured (otherwise you get the separate 'no deployment targets found' error).
Example fix
# before $ hugo deploy --target=prod # config only defines 'production' # after $ hugo deploy --target=production
Defensive patterns
Strategy: validation
Validate before calling
// Verify a target name exists in config before `hugo deploy --target=...`.
func ValidateDeployTarget(targets []deployconfig.Target, name string) error {
if name == "" { return nil } // empty -> first target
for _, t := range targets {
if t.Name == name { return nil }
}
return fmt.Errorf("deployment target %q not found", name)
} Try / catch
d, err := deploy.New(cfg, fs, targetName, logger)
if err != nil {
return err
} Prevention
- Keep deploy scripts and [[deployment.targets]] names in sync.
- Trim/normalise the --target value.
- Document the canonical target names in the project README.
When it happens
Trigger: `hugo deploy --target=foo` where 'foo' is not among the configured [[deployment.targets]] names; deploying before any target is defined; case/whitespace mismatch in the name.
Common situations: Typo in the --target value; forgetting to add the target to config; renaming a target but not the flag; copy-pasting a deploy command from a different project.
Related errors
- empty deployment matcher
- empty deployment target
- invalid deployment.matchers.pattern
- invalid deployment.orderings.pattern
- invalid deployment.target.exclude
AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09).
Data as JSON: /api/errors/827cb9e05e7cb88f.
Report an issue: GitHub.
Appendix: source
Thrown at deploy/deploy.go:98
if len(dcfg.Targets) == 0 {
return nil, errors.New("no deployment targets found")
}
mediaTypes := cfg.GetConfigSection("mediaTypes").(media.Types)
// Find the target to deploy to.
var tgt *deployconfig.Target
if targetName == "" {
// Default to the first target.
tgt = dcfg.Targets[0]
} else {
for _, t := range dcfg.Targets {
if t.Name == targetName {
tgt = t
}
}
if tgt == nil {
return nil, fmt.Errorf("deployment target %q not found", targetName)
}
}
return &Deployer{
localFs: localFs,
target: tgt,
quiet: cfg.BuildExpired(),
mediaTypes: mediaTypes,
cfg: dcfg,
}, nil
}
func (d *Deployer) openBucket(ctx context.Context) (*blob.Bucket, error) {
if d.bucket != nil {
return d.bucket, nil
}
d.logger.Printf("Deploying to target %q (%s)\n", d.target.Name, d.target.URL)
return blob.OpenBucket(ctx, d.target.URL)View on GitHub (pinned to 52c9bd7908)