notablemind / jupyter-nodejs

A node.js kernel for jupyter/ipython
http://nbviewer.ipython.org/gist/jaredly/404a36306fdee6a1737a
MIT License
682 stars 70 forks source link

Modifying globals (client-side javascript) #55

Open u8sand opened 6 years ago

u8sand commented 6 years ago

Is there any way to modify globals as a workaround for supporting client javascript libraries (in particular) and overcoming the following error:

const jsdom = require('jsdom')
const dom = new jsdom.JSDOM()
window = dom.window
const gapi = require('gapi-client')
ReferenceError: window is not defined
    at Object.<anonymous> (jupyter-nodejs/node_modules/gapi-client/index.js:1:72)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)
    at Module.require (module.js:468:17)
    at require (internal/module.js:20:19)
    at jupyter-nodejs/build/context.js:69:18
    at require (jupyter-nodejs/build/context.js:58:27)

Even though I've 'defined' window, I still receive ReferenceError: window is not defined. This is perhaps because we're stuck in a closure? I was under the impression javascript modified globals by default, I may just not fully understand node-js behavior. Is there a way we could support something like this or a better way to execute client-side libraries in jupyter-nodejs?