d2lang/d2 · error
Object "%s" has "near" set to another object, but layout eng
Error message
Object "%s" has "near" set to another object, but layout engine "%s" only supports constant values for "near". See https://d2lang.com/tour/layouts/#layout-specific-functionality for more.
What it means
FeatureSupportCheck rejects graphs where an object's near is set to another object's key while the layout engine only supports constant near values (no NEAR_OBJECT feature).
Source
Thrown at d2plugin/plugin_features.go:55
for _, obj := range g.Objects {
if obj.Top != nil || obj.Left != nil {
if _, ok := featureMap[TOP_LEFT]; !ok {
return fmt.Errorf(`Object "%s" has attribute "top" and/or "left" set, but layout engine "%s" does not support locked positions. See https://d2lang.com/tour/layouts/#layout-specific-functionality for more.`, obj.AbsID(), info.Name)
}
}
if (obj.WidthAttr != nil || obj.HeightAttr != nil) &&
len(obj.ChildrenArray) > 0 && !obj.IsGridDiagram() {
if _, ok := featureMap[CONTAINER_DIMENSIONS]; !ok {
return fmt.Errorf(`Object "%s" has attribute "width" and/or "height" set, but layout engine "%s" does not support dimensions set on containers. See https://d2lang.com/tour/layouts/#layout-specific-functionality for more.`, obj.AbsID(), info.Name)
}
}
if obj.NearKey != nil {
_, isKey := g.Root.HasChild(d2graph.Key(obj.NearKey))
if isKey {
if _, ok := featureMap[NEAR_OBJECT]; !ok {
return fmt.Errorf(`Object "%s" has "near" set to another object, but layout engine "%s" only supports constant values for "near". See https://d2lang.com/tour/layouts/#layout-specific-functionality for more.`, obj.AbsID(), info.Name)
}
}
}
}
if _, ok := featureMap[DESCENDANT_EDGES]; !ok {
for _, e := range g.Edges {
// descendant edges are ok in sequence diagrams
if e.Src.OuterSequenceDiagram() != nil || e.Dst.OuterSequenceDiagram() != nil {
continue
}
if !e.Src.IsContainer() && !e.Dst.IsContainer() {
continue
}
if e.Src == e.Dst {
return fmt.Errorf(`Connection "%s" is a self loop on a container, but layout engine "%s" does not support this. See https://d2lang.com/tour/layouts/#layout-specific-functionality for more.`, e.AbsID(), info.Name)
}
if e.Src.IsDescendantOf(e.Dst) || e.Dst.IsDescendantOf(e.Src) {
return fmt.Errorf(`Connection "%s" goes from a container to a descendant, but layout engine "%s" does not support this. See https://d2lang.com/tour/layouts/#layout-specific-functionality for more.`, e.AbsID(), info.Name)View on GitHub (pinned to 0d69dca6f5)
Solutions
- Switch to ELK, which supports object-relative near
- Remove the near attribute and use constant positions
- Reorder declaration or restructure containers to get desired placement
Example fix
// before b.near: a // after b.near: top-center // or use layout: elk
Defensive patterns
Strategy: validation
Validate before calling
for _, obj := range g.Objects {
if obj.NearKey != nil && engineName != "elk" {
if isKey, _ := g.Root.HasChild(d2graph.Key(obj.NearKey)); isKey {
// object-near unsupported; rewrite
}
}
} Try / catch
if err := engine.FeatureSupportCheck(ctx, g); err != nil {
return fmt.Errorf("near-object unsupported: %w", err)
} Prevention
- Use constant near values (top-center etc.) with non-ELK engines
- Keep object-relative positioning restricted to ELK diagrams
- Validate diagrams with FeatureSupportCheck before layout
When it happens
Trigger: obj.NearKey is a key that resolves to another object in the graph root (g.Root.HasChild succeeds) and the engine lacks NEAR_OBJECT.
Common situations: Writing `b.near: a` to position b relative to a while using dagre, which only supports near: top-center style constants.
Related errors
- Object "%s" has attribute "top" and/or "left" set, but layou
- Object "%s" has attribute "width" and/or "height" set, but l
- Connection "%s" is a self loop on a container, but layout en
- Connection "%s" goes from a container to a descendant, but l
- no actors declared in sequence diagram
AI-assisted analysis of d2lang/d2@0d69dca6f5 (2026-08-31).
Data as JSON: /api/errors/84eb61597d7f7377.
Report an issue: GitHub.