Module tips and tricks

Hi all,

Are there any tips and tricks for non-UMD modules - in particular, any handy utilities to get the packages to play nicely with Observable? Here are a couple of examples:


Hey Simon,

Sure thing! These are both resolveable with one of the methods in my stubborn modules notebook - specifically the 'module that attaches a variable to the window but doesn’t implement UMD one - try

Nt = require('').catch(()=>window.Nt)


binaryheap = require('').catch(()=>window.binaryheap)

Dear Tom,

Thanks - I’ve looked through your modules notebook, but didn’t put 2 and 2 together in the case where one isn’t globbing on to another module (as in your notebook), rather just adding something to the global namespace.


Dear Tom,

What about code that isn’t wrapped up in a module of any kind? e.g.

Oops, this was a bug in d3-require, which is used by Observable to implement require! d3-require is supposed to ignore the names in asynchronous module definitions such as cellauto:

Instead, it thought that cellauto depended on various single-letter modules (“C”, “e”, “l”, ”l”, “A”, etc.). This has been fixed in d3-require 0.6.4 and will be deployed shortly to Observable.

Dear @mbostock @tom

Thanks! Is this also the reason I can’t load gpu.js?


there are quite a bunch of examples with gpu.js

Thanks @Fil - serves me right for not checking regularly! When I tried previously, I got an error…

As side issue is that searching for “gpu.js” doesn’t bring results => 0 => lots

Dear @mbostock

Thanks! The following works.

CellAuto = require("").catch(()=>window.CellAuto)

Glad to hear it! That catch block shouldn’t be necessary anymore, since cellauto.js is a valid AMD. You can say:

CellAuto = require("")