d2lang/d2 · error
Object "%s" has attribute "width" and/or "height" set, but l
Error message
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.
What it means
FeatureSupportCheck rejects graphs where a container object has explicit width/height set, but the layout engine did not declare the CONTAINER_DIMENSIONS feature. Engines that lay out containers automatically cannot honor forced container dimensions.
Source
Thrown at d2plugin/plugin_features.go:47
if info.Features == nil {
return nil
}
featureMap := make(map[PluginFeature]struct{}, len(info.Features))
for _, f := range info.Features {
featureMap[f] = struct{}{}
}
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
}View on GitHub (pinned to 0d69dca6f5)
Solutions
- Remove width/height from containers and let the engine size them
- Switch to a layout engine supporting container dimensions (e.g. ELK)
- Convert the container to a grid diagram (grid-rows/grid-columns), which is exempt
Example fix
// before
container: { width: 500; a; b }
// after
container: { a; b } // or use layout: elk Defensive patterns
Strategy: validation
Validate before calling
for _, obj := range g.Objects {
if (obj.WidthAttr != nil || obj.HeightAttr != nil) && len(obj.ChildrenArray) > 0 && !obj.IsGridDiagram() && engineName != "elk" {
// strip width/height or switch engine
}
} Try / catch
if err := engine.FeatureSupportCheck(ctx, g); err != nil {
return fmt.Errorf("container dimensions unsupported: %w", err)
} Prevention
- Avoid explicit sizes on containers unless using ELK
- Prefer grid layouts for fixed-size containers
- Call FeatureSupportCheck in CI for authored diagrams
When it happens
Trigger: An object with children (a container, non-grid) has WidthAttr or HeightAttr set and the engine lacks CONTAINER_DIMENSIONS.
Common situations: Setting explicit sizes on boxes that contain other boxes while using dagre; diagrams authored for ELK reused with another engine.
Related errors
- Object "%s" has attribute "top" and/or "left" set, but layou
- Object "%s" has "near" set to another object, but layout eng
- 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/2f289973b36fb4c1.
Report an issue: GitHub.