badeball / karma-jsdom-launcher

A Karma plugin. Launcher for jsdom.
MIT License
37 stars 16 forks source link

Intermittent `Cannot read property 'prototype' of undefined` error #22

Closed binomialstew closed 6 years ago

binomialstew commented 6 years ago

I have been getting this error intermittently. It started failing again after other seemingly unrelated dependency changes.

Error during loading "~/project/node_modules/karma-jsdom-launcher" plugin:
  Cannot read property 'prototype' of undefined

If I replace jsdom with phantomjs and its corresponding launcher, my tests run with no issue, and my tests ran with no issue previously with the same configuration I have now using the jsdom browser and karma-jsdom-launcher for at least 6 months.

In the past, it seemed like it may have something to do with the node version, but I haven't updated node recently on the system in question.

My current versions:

node v8.9.4
karma-jsdom-launcher v6.1.3
karma v1.7.1
jsdom v11.12.0

The first time I saw this error, it was on a remote server with an older node version (6, I believe). This is after it had been running successfully for a while under that version. I was not able to reproduce locally at that time. Now I am seeing it locally, as well. I was unable to find any differences that would explain this between the current state of my dependencies and before, when it was running successfully.

edm00se commented 6 years ago

I'm experiencing something very close to this. I'm similarly able to run fine with no issues with karma-phantomjs-launcher (latest, 1.0.4) but failing when using karma-jsdom-launcher. I'm running from Windows (7 Pro) PowerShell, my installed versions are:

node: 8.11.2
karma: 1.7.1
karma-jsdom-launcher: 6.1.3
jsdom: 11.12.0
The exact error I'm given is `Error: "value" required in setHeader("Referer", value)`. Expand for the full log.

```sh PS C:\Users\..path\to\app> npm t > cfc-vendor-lib@1.0.0 test C:\Users\..path\to\app > karma start karma.conf.js [2018-08-10 13:43:36.084] [INFO] karma - Karma v1.7.1 server started at http://0.0.0.0:9876/ [2018-08-10 13:43:36.085] [INFO] launcher - Launching browser jsdom with unlimited concurrency [2018-08-10 13:43:36.103] [INFO] launcher - Starting browser jsdom [2018-08-10 13:43:36.228] [ERROR] karma - Error: "value" required in setHeader("Referer", value) at validateHeader (_http_outgoing.js:489:11) at ClientRequest.setHeader (_http_outgoing.js:498:3) at new ClientRequest (_http_client.js:173:14) at Object.request (http.js:38:10) at Request.start (C:\Users\..path\to\app\node_modules\request\request.js:708:30) at Request.end (C:\Users\..path\to\app\node_modules\request\request.js:1405:28) at end (C:\Users\..path\to\app\node_modules\request\request.js:433:16) at C:\Users\..path\to\app\node_modules\request\request.js:447:9 at _combinedTickCallback (internal/process/next_tick.js:131:7) at process._tickCallback (internal/process/next_tick.js:180:9) npm ERR! Test failed. See above for more details. ```

badeball commented 6 years ago

@binomialstew, I will try to have a look at this as soon as I can.

@edm00se, when one does change from EG. phantomjs to jsdom, you also change request implementation. That of webkit (phantomjs) might be more lenient than jsdom, thus allowing you to actually specify a blank referrer. Are you doing anything like that?

edm00se commented 6 years ago

@badeball I'm not doing anything (myself) with referrers or anything, pretty basic tests in fact.

binomialstew commented 6 years ago

I found that this seems to be related to the request dependency of jsdom. Pinning request to version 2.83 corrects the problem for me.

badeball commented 6 years ago

@binomialstew, I'll assume that to be correct for now and thus consider this to be solved.

If the issues persist - I encourage people to try to provide a minimal example to re-produce the issue. Preferably with a full package-lock, to ensure that the example continues to produce it.