I’m getting “global is undefined” when d3-graphviz is about to call Viz. The notebook shows that Viz is working when used directly, but not when called through d3-graphviz.
A similar example works outside of Observable:
I’m pretty sure it has something to do with module loading, but this is terra incognita for me.
How can I debug this better?
Is there a way to get normal stack traces in Observable?
I made a local debug version of d3-graphviz, but when I try to load it from a local server, I get “Error: unable to load module”. Is it only possible to load libraries from unpkg?
Since the error is the same, I suspect that I haven’t been able to load viz.js correctly in the first example or that I use Viz incorrectly in d3-graphviz, but in a way that works when run outside Observable.
I’m not sure I answered your question though
The error I’m getting on your notebook is a bit different than what you have written down: Cannot read property 'Int8Array' of undefined
Thanks. Actually I started out with a fork of that notebook with the intention to add animated transitions to it with d3-graphviz, but couldn’t get it to work. Hopefully, I can come back with that soon now that I’ve gotten help.
@mbostock d3-graphviz is only 41 KB (15 KB minified) in itself. You’re probably comparing viz-lite.js with a bundle containing d3-graphviz, the full version of viz.js and some d3 core modules. The difference between viz-lite.js and viz.js is around 0.6 MB.
Where did you get the numbers from?
I would expect that the overhead added by d3-graphviz and the d3 core modules is negligible when comparing with viz.js or viz-lite.js.
I got 2.78 MB for that link before I released a new version of d3-graphviz with viz.js upgraded to v1.8.1 which reduces the size of the bundle with 0.53 MB.
I did a little more digging and this appears to be a problem with Viz.js 1.8.1, which uses a newer version of Emscripten than 1.8.0. So, this works fine:
Viz = require("viz.js@1.8.0/viz.js").catch(() => window.Viz)
html`${Viz("digraph {a -> c}")}`
But, if you change 1.8.0 to 1.8.1, you get TypeError: Cannot read property ‘Int8Array’ of undefined.
The doubly strange thing is that @observablehq/graphviz uses Viz.js-lite 1.8.1 and has no problems.
And a little more digging… Viz.js 1.8.1 has a broken UMD block that causes it to export the Emscripten-generated Module rather than Viz. I’ve filed a bug here: