6

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.

ccnokes
  • 6,885
  • 5
  • 47
  • 54
  • 1
    I am facing a similar issue but with `exit code 1` – TechSpellBound Apr 01 '15 at 10:25
  • In line to my previous comment, the issue (that I mentioned in the comment) got resolved for me in Ubuntu 14.04 by deleting the `node_modules` directory from the project (which had been checked-in by someone else using a Macbook). I ran `npm install` again and the `node_modules` directory was recreated. We have also added the `node_modules` directory to `.gitignore` to avoid this issue in future. – TechSpellBound Apr 01 '15 at 11:02
  • Interesting, I'll have to try it again when I get a chance. I was using Vagrant with a Mac host, so that could explain it. I'll post the results when I test it out later. – ccnokes Apr 01 '15 at 17:06
  • If it is related to Mac Os Sierra, Please change the version to 1.0.0 or above – Ravikiran Reddy Kotapati Feb 08 '17 at 12:29

3 Answers3

3

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

Ravikiran Reddy Kotapati
  • 2,485
  • 3
  • 22
  • 27
1

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

Splaktar
  • 5,506
  • 5
  • 43
  • 74
1

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..

jforberg
  • 6,537
  • 3
  • 29
  • 47
sg28
  • 1,363
  • 9
  • 19