Karma: Cannot start PhantomJS

Created on 19 Dec 2014  Β·  21Comments  Β·  Source: karma-runner/karma

Hello, this seems to be somewhat related to issue #558. However I'm new to all this (npm, grunt, karma) and I'm not really sure of the identity of the problem.

When I
grunt karma:unit
I get this sad result

Running "karma:unit" (karma) task
INFO [karma]: Karma v0.12.28 server started at http://localhost:8080/
INFO [launcher]: Starting browser PhantomJS
ERROR [launcher]: Cannot start PhantomJS
    Error: spawn EACCES
INFO [launcher]: Trying to start PhantomJS again (1/2).
ERROR [launcher]: Cannot start PhantomJS
    Error: spawn EACCES
INFO [launcher]: Trying to start PhantomJS again (2/2).
ERROR [launcher]: Cannot start PhantomJS
    Error: spawn EACCES
ERROR [launcher]: PhantomJS failed 2 times (cannot start). Giving up.
Warning: Task "karma:unit" failed. Use --force to continue.
Aborted due to warnings.

With my limited understanding I've tried installing and reinstalling (global and/or not) phantomjs but it didn't work out.

I'm on Ubuntu 12.04
[email protected]
[email protected]
[email protected]

However, when I $ phantomjs --version, I get 1.9.8. which is odd. Checking on the phantomjs website seems to confirm the latests release is phantomjs 1.9.8.

$ npm remove phantomjs -g
unbuild [email protected]
$ npm remove phantomjs
unbuild [email protected]
$  phantomjs --version
bash: ~/.npm-packages/bin/phantomjs: No such file or directory

So I don't think there's another installation that karma could refer to. At this point, when I launch grunt karma:unit it accordingly say that phantomjs isn't there.

Then I reinstalled phantomjs

$ npm install phantomjs

> [email protected] install ~/mytodo/node_modules/phantomjs
> node install.js

Downloading https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.8-linux-x86_64.tar.bz2
Saving to /tmp/phantomjs/phantomjs-1.9.8-linux-x86_64.tar.bz2
Receiving...
  [======================================--] 95% 0.0s
Received 12854K total.
Extracting tar contents (via spawned process)
Removing /media/Fermi/workspace/mytodo/node_modules/phantomjs/lib/phantom
Copying extracted folder /tmp/phantomjs/phantomjs-1.9.8-linux-x86_64.tar.bz2-extract-1418991182513/phantomjs-1.9.8-linux-x86_64 -> ~/mytodo/node_modules/phantomjs/lib/phantom
Removing /tmp/phantomjs/phantomjs-1.9.8-linux-x86_64.tar.bz2-extract-1418991182513
Writing location.js file
Done. Phantomjs binary available at ~/mytodo/node_modules/phantomjs/lib/phantom/bin/phantomjs
[email protected] node_modules/phantomjs
β”œβ”€β”€ [email protected]
β”œβ”€β”€ [email protected]
β”œβ”€β”€ [email protected]
β”œβ”€β”€ [email protected]
β”œβ”€β”€ [email protected]
β”œβ”€β”€ [email protected]
β”œβ”€β”€ [email protected] ([email protected])
β”œβ”€β”€ [email protected] ([email protected])
β”œβ”€β”€ [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
└── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])

Still, karma complains Cannot start PhantomJS Error: spawn EACCES.

Most helpful comment

Just wanted to note, as I had a similar issue today - phantomjs on Ubuntu needs the libfontconfig package (and/or the libfontconfig-dev package - I installed both) or it won't start..

All 21 comments

@etiennebr remove global phantomjs and install it to the project

Nope :(

$ npm remove phantomjs
$ npm remove phantomjs -g
$ npm install phantomjs

Then still that error...

$ grunt karma:unit
[...]
ERROR [launcher]: Cannot start PhantomJS
    Error: spawn EACCES
[...]

Do you have env variable PHANTOMJS_BIN?

echo $PHANTOMJS_BIN

I added it to my .bashrc. ~/mytodo/node_modules/phantomjs/lib/phantom/bin/phantomjs.
And I should be able to execute.

ls -l $PHANTOMJS_BIN 
-rwxr-xr-x 1 etienne etienne 38346752 dec 19 09:21 ~/mytodo/node_modules/phantomjs/lib/phantom/bin/phantomjs

@etiennebr seems karma does not have access to this file.
Try remove/unset variable PHANTOMJS_BIN and run karma in project.

@etiennebr karma installed locally?

How can I change access for karma ? I removed karma globally and installed it locally only, but still the same issue.

$ npm remove karma -g
$ npm remove karma
$ npm install karma
$ grunt karma
[...]
ERROR [launcher]: Cannot start PhantomJS
    Error: spawn EACCES
[...]

While installation seems to work fine, karma isn't in ./node_modules/.bin/karma[1] but in ./node_modules/karma/bin/karma, looking around, I think it's normal though.

$ ./node_modules/karma/bin/karma start
bash: ./node_modules/karma/bin/karma: Permission denied
$ ls -l ./node_modules/karma/bin/karma
-rwxrwxrwx 1 etienne etienne 50 nov 25 10:26 ./node_modules/karma/bin/karma

Now after some googling it seems related to file access, and similar to http://stackoverflow.com/questions/26968388/executing-karma-giving-permission-denied-error, but chmod 777 didn't make it. On phantomjs issues, I found https://github.com/Medium/phantomjs/issues/102, but using sudo doesn't seem to apply; I've used this solution instead https://github.com/sindresorhus/guides/blob/master/npm-global-without-sudo.md.

1: the directory stated in doc http://karma-runner.github.io/0.8/intro/installation.html

Hm... really very strange behavior. Myself I use _Ubuntu_ and never met such problems on _12_ and _14_

As a suggestion try use nvm and install karma-cli globally for running karma from console(karma start):

npm install -g karma-cli

Thanks!

Close, because problem does not in karma itself.

Just wanted to note, as I had a similar issue today - phantomjs on Ubuntu needs the libfontconfig package (and/or the libfontconfig-dev package - I installed both) or it won't start..

@egeland Your solution fixed the problem. The package was missing on my Ubuntu. I got following error message:

INFO [karma]: Karma v0.12.37 server started at http://localhost:9018/
INFO [launcher]: Starting browser PhantomJS
ERROR [launcher]: Cannot start PhantomJS

INFO [launcher]: Trying to start PhantomJS again (1/2).
ERROR [launcher]: Cannot start PhantomJS

INFO [launcher]: Trying to start PhantomJS again (2/2).
ERROR [launcher]: Cannot start PhantomJS

ERROR [launcher]: PhantomJS failed 2 times (cannot start). Giving up.

Unfortunately this message does not give any hints about the problem, so I'm happy that I found your post.

@dominicumbeer Glad it helped - your errors are exactly what I was seeing today.

So mysterious, until you run phantomjs by itself (not with --version), then you see the cause..

@egeland : Good thing I found this post. I'm also having problems with PhantomJS not running in Karma in Meteor's velocity JS

Kudos to you :)

@egeland Me too!

npm install phantomjs
npm install grunt-karma
npm install karma
npm install karma-cli
npm install karma-phantomjs-launcher

grunt karma & karam start & sudo karam start all not work, but sudo grunt karma works fine

  βœ— karma start
ERROR [launcher]: Cannot start PhantomJS
    Error: spawn EACCES
ERROR [launcher]: Cannot start PhantomJS
    Error: spawn EACCES
ERROR [launcher]: Cannot start PhantomJS
    Error: spawn EACCES
ERROR [launcher]: PhantomJS failed 2 times (cannot start). Giving up.
------
βœ— sudo karma start
Password:

sudo karma start is stuck

@luxueyan Did you install the packages as I mentioned above?
Did you try running phantomjs by itself, no options?

@egeland Sorry, i didn't say my system is os x 10.9.5.
I run phantomjs by itself well without any options.
In my project

node_modules/phantomjs/bin/phantomjs

Now the only works way for me is : sudo grunt karma.
Thanks!

@egeland +1 to your solution. Thank you very much for helping us !

RHEL/CentOS solution:

yum install -y fontconfig freetype-devel

i think libfontconfig-dev isnt required (debian:jessie)

@egeland Thank you so much! You saved my day!

Just a note for others that we came across this issue when the script being executed wasn't actually executable. That is, a simple chmod +x SCRIPT_NAME fixed it for us.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wellyshen picture wellyshen  Β·  4Comments

schippie picture schippie  Β·  5Comments

macjohnny picture macjohnny  Β·  5Comments

mgol picture mgol  Β·  3Comments

ebacka picture ebacka  Β·  3Comments