"ReferenceError: window is not defined" in browserifed jsdom

209 views
Skip to first unread message

Hugo Ferreira

unread,
Oct 22, 2019, 10:24:03 AM10/22/19
to jsdom
Hello,

using a locally installed version of jsdom via npm. I have used the HTML test file shown and also used
jsdom in the console as shown. This is working - HTML loads and script command works.

I then used the same jsdom and "loaded" that into the GraalJS engine. I get this error (full stack trace in
the end):

Exception in thread "main" ReferenceError: window is not defined
    at <js> 140(mdocs/src/mdocs/jsdom.js:31238:1099420-1099425)
    at <js> o(mdocs/src/mdocs/jsdom.js:1:621-708)
    at <js> :anonymous(mdocs/src/mdocs/jsdom.js:1:680-686)
    at <js> :anonymous(mdocs/src/mdocs/jsdom.js:142276:4252481-4252500)


I now generated a debug version of the browserify jsdom - a 17 Mega behemoth.
The lines that is causing all this heartache is:

},{"http":961,"https":888,"net":783,"tls":783,"util":987}],140:[function(require,module,exports){
/* eslint-env browser */
module.exports = typeof self == 'object' ? self.FormData : window.FormData;   <--------------------

},{}],141:[function(require,module,exports){

Is their any way of getting around this? A google search shows this type of problems
occurs in many cases. However I don't have the know-how to solve this. One solution
seems to indicate that I may need to configure ESLint to /* eslint-env browser node */.
If so, how can I set this? Can this be an issue in the GraalJS?

BTW, given the debug version of the bundle how do I track which require(module) is the culprit?

TIA


Full stack trace.


Exception in thread "main" ReferenceError: window is not defined
    at <js> 140(mdocs/src/mdocs/jsdom.js:31238:1099420-1099425)
    at <js> o(mdocs/src/mdocs/jsdom.js:1:621-708)
    at <js> :anonymous(mdocs/src/mdocs/jsdom.js:1:680-686)
    at <js> :anonymous(mdocs/src/mdocs/jsdom.js:142276:4252481-4252500)
    at <js> 687(mdocs/src/mdocs/jsdom.js:142261-143814:4252049-4296614)
    at <js> o(mdocs/src/mdocs/jsdom.js:1:621-708)
    at <js> :anonymous(mdocs/src/mdocs/jsdom.js:1:680-686)
    at <js> 668(mdocs/src/mdocs/jsdom.js:139149:4165326-4165345)
    at <js> o(mdocs/src/mdocs/jsdom.js:1:621-708)
    at <js> :anonymous(mdocs/src/mdocs/jsdom.js:1:680-686)
    at <js> :anonymous(mdocs/src/mdocs/jsdom.js:102383:3166269-3166286)
    at <js> 589(mdocs/src/mdocs/jsdom.js:102381-102802:3166219-3178974)
    at <js> o(mdocs/src/mdocs/jsdom.js:1:621-708)
    at <js> :anonymous(mdocs/src/mdocs/jsdom.js:1:680-686)
    at <js> :anonymous(mdocs/src/mdocs/jsdom.js:103017:3186199-3186220)
    at <js> 594(mdocs/src/mdocs/jsdom.js:103006-104101:3185810-3222104)
    at <js> o(mdocs/src/mdocs/jsdom.js:1:621-708)
    at <js> :anonymous(mdocs/src/mdocs/jsdom.js:1:680-686)
    at <js> :anonymous(mdocs/src/mdocs/jsdom.js:38284:1372041-1372075)
    at <js> 191(mdocs/src/mdocs/jsdom.js:38268-38949:1371206-1392365)
    at <js> o(mdocs/src/mdocs/jsdom.js:1:621-708)
    at <js> :anonymous(mdocs/src/mdocs/jsdom.js:1:680-686)
    at <js> :anonymous(mdocs/src/mdocs/jsdom.js:205464:6361572-6361607)
    at <js> jsdom(mdocs/src/mdocs/jsdom.js:205451-205782:6361033-6371410)
    at <js> o(mdocs/src/mdocs/jsdom.js:1:621-708)
    at <js> :anonymous(mdocs/src/mdocs/jsdom.js:1-205784:366-6371877)
    at <js> :anonymous(mdocs/src/mdocs/jsdom.js:1:314-316)
    at <js> :program(mdocs/src/mdocs/jsdom.js:1-205785:1-6371880)
    at <js> :program(Unnamed:3:2-35)
    at org.graalvm.sdk/org.graalvm.polyglot.Context.eval(Context.java:370)
    at mdocs.TestGraalJSDOM$.executePolyglotJS_3(TestGraalJSDOM.scala:393)
    at mdocs.TestGraalJSDOM$.main(TestGraalJSDOM.scala:448)
    at mdocs.TestGraalJSDOM.main(TestGraalJSDOM.scala)

Reply all
Reply to author
Forward
0 new messages