d2 icon indicating copy to clipboard operation
d2 copied to clipboard

Imports on Windows are not relative to diagram path

Open andrewschmidgit opened this issue 1 year ago • 5 comments

According to https://d2lang.com/tour/imports/#imports-are-relative-to-that-file

image

Directory structure:

.
└── diagrams
    ├── architecture.d2
    ├── flow--queue.d2
    └── styles.d2

flow--queue.d2 includes styles.d2 with:

...@styles

When I run d2 from the .\ directory, I get an error (... replaces project directory):

err: failed to compile diagrams\flow--queue.d2: ...\diagrams\flow--queue.d2:1:1: failed to import "styles.d2": open styles.d2: The system cannot find the file specified.

When I run d2 from the diagrams\ directory, it succeeds:

success: successfully compiled flow--queue.d2 to flow--queue.svg in 1.5866772s

andrewschmidgit avatar Jun 05 '24 16:06 andrewschmidgit

I came across the same issue with icon import on Linux

am-on avatar Aug 06 '24 11:08 am-on

@am-on wasn't running the right version. @andrewschmidgit were you running on latest version?

alixander avatar Sep 16 '24 15:09 alixander

It's on v0.6.5

andrewschmidgit avatar Sep 16 '24 20:09 andrewschmidgit

@andrewschmidgit Can you update and try on 0.6.6?

alixander avatar Sep 17 '24 01:09 alixander

I am running on 0.6.8 and using a devcontainer in vscode on mac os and seem to having issues with this as well.

models
|-- assets
|   |-- aws
|   |   |-- eks.svg
|   |   |-- nlb.svg
|   |   |-- subnet.svg
|   |   |-- vpc.svg
|   |   `-- vpce.svg
|   |-- k8s
|   |   |-- deploy.svg
|   |   |-- istio.png
|   |   |-- k8s.svg
|   |   |-- ns.svg
|   |   |-- pod.svg
|   |   `-- svc.png
|-- aws.d2
|-- istio.d2
|-- k8s.d2
`-- position.d2

I reference icons like assets/k8s/svc.png

If I render models/aws.d2 directly then the icons work.

If I render cell-deply.d2 (that is in the root folder called diagrams above models) then I get the following errors:

err: failed to bundle ./assets/aws/eks.svg: open /workspaces/scratch-test/diagrams/assets/aws/eks.svg: no such file or directory
err: failed to bundle ./assets/aws/subnet.svg: open /workspaces/scratch-test/diagrams/assets/aws/subnet.svg: no such file or directory
err: failed to bundle ./assets/aws/vpc.svg: open /workspaces/scratch-test/diagrams/assets/aws/vpc.svg: no such file or directory
err: failed to compile cell-deploy.d2: failed to bundle local images: [./assets/aws/eks.svg ./assets/aws/subnet.svg ./assets/aws/vpc.svg]

So it still looks like the cell-deploy.d2 file is taking the raw icon path and not adding the models/ path before rendering...

Note I reference the models in the root diagrams like so:

vpc: @models/aws.vpc

vpc: {
  az1: @models/aws.az
  az2: @models/aws.az
  az3: @models/aws.az
}

pvdvreede avatar Dec 09 '24 23:12 pvdvreede

I have the same issue @andrewschmidgit in version 0.7.0

KEBO80 avatar Jun 20 '25 08:06 KEBO80