Jupyter Notebook - underscore.js doesn't seem to be accessible anymore

67 Views Asked by At

I'm using a custom widget in Jupyter. After upgrading to a new machine it stopped functioning. Checking the javascript console in the browser window running the notebook I see the error ReferenceError: _ is not defined. Indeed, running the following in a Jupyter cell:

%%js
alert(_)

I get the same error. Doing the exact same command on my other machine functions correctly (it shows the definition of _ as in underscore.js). The html source of the Jupyter Notebook still shows underscore.js as being specified in the require.config. Note that simple included widgets still function as expected (so it is not an issue with initializing the widget system).

I haven't found anything in the changelogs of ipywidgets or jupyter regarding changes to the use of underscore.js. I know that the widget api has changed recently in ipywidgets8.0, which is why I am still using version 7.7.3.

Does anyone know if this is an expected change of behaviour in how widgets work? Any other ideas of why underscore does not seem to be initialized properly?

1

There are 1 best solutions below

0
On BEST ANSWER

Underscore.js is available in the 6.4.x series e.g. pip install notebook=6.4.12

It broke in your case likely because js assets were delegated to NbClassic starting with 6.5, which I'm guessing doesn't load underscore.js (or doesn't make it available to the notebook frontend). See github.com/jupyter/notebook/pull/6474.