I get an error saying: LexiconMonoSeq = TypeError: Cannot read property âaddEventListenerâ of undefined
I cannot see the line of the error so I am guessing that some names are reserved such as window or document, so I went ahead and changed them to $window and $document respectively and published the current version. However I still get the error.
I see absolutely nothing on the developer console either. Can someone break down what is going on behind the scenes so I can get this up and working.
Welcome to Observable! Sorry youâre running into some issues with this. For the debugging strategy, because this is happening in a required module and thereâs an error happening in it, the best first approach is to toggle âPause on uncaught exceptionsâ on in the âSourceâ tab of the Chrome Developer Tools,
Or in Firefox, the âPause on exceptionsâ checkbox under the Debugger tab
What this turns up is pretty much what youâve already identified, but youâll get a specific spot in the code where it occurs:
So next up is going up a level: $window is not defined, so where is this function being called with an undefined $window argument? We set a breakpoint right at the top in the UMD definition, and youâll get
So out of the three options (AMD, CommonJS, and global), we can see that itâs taking the AMD path, the first one - because define is a function and has an amd property. And, in contrast to the other two paths, we arenât explicitly passing root or root.document through. Per the AMD spec, itâll call factory for you after loading any dependencies, and since in this case the dependencies array is [], itâs just going to call factory with no arguments.
So (Iâm no AMD expert), but from my reading, AMD dependencies are really only other files and factor methods tend not to pass window & document in this way, so I posted a PR on the project that accesses window and document directly, and which works well for all the usage types. Hereâs an example notebook that uses this tweaked version: