-
|
Anyone had any luck running maxgraph headlessly in nodejs, i.e. without a browser? A quick look at the source code reveals it's dependent upon DOM, but often that's easily sorted by installing jsdom. But actually the problem's more fundemental than that: This should be easy, because maxgraph has unit tests, and as such already runs correctly within the nodejs environment, but I'm scratching my head here not able to figure out how to use it. I'm thrilled to be using maxgraph, because I quite often find myself working with graph data that I'd like to visualise, and it seems like a huge upgrade from graphviz, and TypeScript native too, so I'm really excited about it. It'd just be nice to run a program and have it document itself without having to rely on a browser. (The SVG export part is easy too, even if my current implementation is a bit knarly). |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 12 replies
-
|
Hi
maxGraph only provides ECMAScript modules, so this is what explains the error you see. As you mentioned, the tests runs with jsdom and they all use the « import » syntax to load maxGraph elements.
|
Beta Was this translation helpful? Give feedback.
-
|
Wow, you've nailed the problem, thank you so much for your advice! Unfortunately the solution doesn't follow as an exercise for the reader quite as easily as either of us would expect or like. Setting up a nodejs TypeScript project with ESM is a little more ticklish than I'd anticipated. Having gotten that far, I find it breaks when I try to bring in maxgraph: The code I'm running can be found in this example repo It looks like ESM requires the file extension to be given for imports? Which maxgraph doesn't do. Build tools like Vite, and apparently unit test tools like Jest, allow this requirement to be waived, but nodejs does not. I'm still trying to think of a way to work around this, and would welcome your input, if possible. |
Beta Was this translation helpful? Give feedback.
Hi @Antony74 https://github.com/maxGraph/maxGraph/releases/tag/v0.20.0 is available and provides CommonJS support.