1
votes

I'm encountered a problem recently with PhantomJS library.

$ karma start

Log result:

Karma v0.13.15 server started at http://localhost:9876/ Starting browser PhantomJS INFO [PhantomJS 1.9.8 (Mac OS X 0.0.0)]: Connected on socket H1vRWOIqgBCUjb_bAAAA with id 36694801 PhantomJS 1.9.8 (Mac OS X 0.0.0) ERROR TYPE_MISMATCH_ERR: DOM Exception 17: The type of an object was incompatible with the expected type of the parameter associated to the object. at /Users/farman/.../tests.webpack.js:122637 <- webpack:///~/crypto-browserify/rng.js:14:0

PhantomJS 1.9.8 (Mac OS X 0.0.0): Executed 0 of 0 ERROR (2.21 secs / 0 secs)

Module versions:

  • OSX: El Capitan 10.11.1
  • node: 5.0.0
  • Karma: 0.13.15
  • karma-phantomjs-launcher: 0.2.1
  • Phantomjs: 1.9.18

I've checked the forum, but still not solving the issue: https://github.com/AngularClass/angular2-webpack-starter/issues/45

1
Seeing the same error with a React application after recently updating a few dependencies. (Only mentioning this to point out that it's probably not Angular related.) - bvaughn
Looks like crypto-browserify/rng.js points out the likely cause: "This will not work on older browsers" (which I assume includes PhantomJS- unless you polyfill it) - bvaughn
Can verify that patching this function to use Math.random instead did indeed get rid of the issue for me in PhantomJS but that's not really a viable solution. - bvaughn
Looks like updating crypto-browserify/rng.js to use a Uint8Array instead of a Buffer also resolves the error (at least in my initial testing) - bvaughn

1 Answers

0
votes

The crypto-browserify library is using Buffer which is buffer is a modified Uint8Array. PhantonJS apparently has a bug that rejects Buffer though and that's causing the issue you're seeing.

I've filed an issue here: https://github.com/crypto-browserify/crypto-browserify/issues/143

You can also temporarily patch this by updating crypto-browserify/rng.js to replace this...

var bytes = new Buffer(size); //in browserify, this is an extended Uint8Array

...with this...

var bytes = new Uint8Array(size); //in browserify, this is an extended Uint8Array