Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When running karma locally, phantomjs won't start

When running Karma from a local install on my project on my Ubuntu VM, Karma won't run because PhantomJS can't start.

Version info:

  • PhantomJS (also installed locally): 1.9.16
  • Karma: 0.12.31
  • karma-phantomjs-launcher: 0.1.4
  • Ubuntu 14.04.2 LTS
  • Node 0.10.25

The same script runs just fine on my Mac OS (I removed global installs of karma before running it and it still worked).

On Ubuntu, If I start phantomjs directly via ./node_modules/phantomjs/bin/phantomjs, it starts just fine.

Here's the shell output:

> ./node_modules/karma/bin/karma start test/karma.conf.js

DEBUG [config]: autoWatch set to false, because of singleRun
DEBUG [plugin]: Loading karma-* from /srv/detectiveui/node_modules
DEBUG [plugin]: Loading plugin /srv/detectiveui/node_modules/karma-jasmine.
DEBUG [plugin]: Loading plugin /srv/detectiveui/node_modules/karma-phantomjs-launcher.
DEBUG [plugin]: Loading plugin /srv/detectiveui/node_modules/karma-spec-reporter.
INFO [karma]: Karma v0.12.31 server started at http://localhost:9876/
INFO [launcher]: Starting browser PhantomJS
DEBUG [temp-dir]: Creating temp dir at /tmp/karma-42625347
DEBUG [launcher]: /srv/detectiveui/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/bin/phantomjs /tmp/karma-42625347/capture.js
DEBUG [launcher]: Process PhantomJS exited with code 2
ERROR [launcher]: Cannot start PhantomJS

DEBUG [temp-dir]: Cleaning temp dir /tmp/karma-42625347
INFO [launcher]: Trying to start PhantomJS again (1/2).
DEBUG [launcher]: Restarting PhantomJS
DEBUG [temp-dir]: Creating temp dir at /tmp/karma-42625347
DEBUG [launcher]: /srv/detectiveui/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/bin/phantomjs /tmp/karma-42625347/capture.js /tmp/karma-42625347/capture.js
DEBUG [watcher]: Resolved files:
    #...List of my files here that look correct...
DEBUG [launcher]: Process PhantomJS exited with code 2
ERROR [launcher]: Cannot start PhantomJS

DEBUG [temp-dir]: Cleaning temp dir /tmp/karma-42625347
INFO [launcher]: Trying to start PhantomJS again (2/2).
DEBUG [launcher]: Restarting PhantomJS
DEBUG [temp-dir]: Creating temp dir at /tmp/karma-42625347
DEBUG [launcher]: /srv/detectiveui/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/bin/phantomjs /tmp/karma-42625347/capture.js /tmp/karma-42625347/capture.js /tmp/karma-42625347/capture.js
DEBUG [launcher]: Process PhantomJS exited with code 2
ERROR [launcher]: Cannot start PhantomJS

DEBUG [temp-dir]: Cleaning temp dir /tmp/karma-42625347
ERROR [launcher]: PhantomJS failed 2 times (cannot start). Giving up.

DEBUG [karma]: Run complete, exiting.
DEBUG [launcher]: Disconnecting all browsers

I also seem to be able to start a node server manually at port 9876, so that's probably not the issue either.

Any help would be greatly appreciated. Thanks!

----UPDATE

I created a new Ubuntu environment and tested the same thing again and got the same error.

like image 812
ccnokes Avatar asked Mar 13 '15 15:03

ccnokes


3 Answers

I faced the same problem, I change the karma-phantomjs-launcher to "^1.0.0" in the package.json file. After the change, Phantomjs started working

like image 74
Ravikiran Reddy Kotapati Avatar answered Nov 10 '22 01:11

Ravikiran Reddy Kotapati


Installing libfontconfig via sudo apt-get install libfontconfig may solve this.

like image 22
Splaktar Avatar answered Nov 10 '22 02:11

Splaktar


I faced the same issue,the solution that worked for me is to run sudo yum install fontconfig , The command has to be executed at the right location, but this works..

like image 20
sg28 Avatar answered Nov 10 '22 02:11

sg28