Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot connect PhantomJS and Poltergeist in Rails application

I've followed the instructions on Poltergeist github page but i keep getting an error that my PhantomJS version is wrong.

Specifically, it says:

Could not find an executable 'phantomjs' that matched the requirements '~> 1.8', '>= 1.8.1'. Found versions were {"/home/marko/projects/irs_machine/bin/phantomjs"=>"50"}.

Now, I have downloaded phantomjs v1.8.1 (and later v1.9.2) so the version is correct. This is really driving me crazy. I use Ubuntu 13.04, but I doubt that's the reason.

Googling for the error returns nothing of use.

Any ideas?

like image 880
Marko Kacanski Avatar asked Sep 16 '13 10:09

Marko Kacanski


2 Answers

I've solved it!

What I found to be very strange was the fact that the error reported the phantomjs version to be "50" which is impossible.

I've tracked the error down to the "cliver" gem, a gem that detects versions of installed programs. It does so by regex matching the desired version string to the result of

 {command} -v

Now, when I run phantomjs -v i get "1.8.1", so what was happening? On closer inspection "1.8.1" wasn't all that I was getting back! To be precise, I got this:

 phantomjs -v
 Fontconfig warning: "/etc/fonts/conf.d/50-user.conf", line 9: reading configurations from ~/.fonts.conf is deprecated.
 1.8.1

I had a fontconf error, and sure enough, the first number it contained was "50". Cliver matches against standard output, so it couldn't get a proper version because the system was writing errors out.

Once I reconfigured the 50-user.conf not to use line 9, the error was gone and poltergeist started working as expected.

like image 62
Marko Kacanski Avatar answered Oct 23 '22 21:10

Marko Kacanski


In my case, using apt-get to install PhantomJS was installing an older version of PhantomJS. I had to manually install PhantomJS by downloading the tarball, unpacking it, and creating links to the executable in /bin:

  1. If you haven't already, remove the outdated version of PhantomJS you have installed.
    Using apt-get, the command for me was sudo apt-get remove phantomjs.
  2. Download the tarball from http://phantomjs.org/download.html.
    (You can use, for example, wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.7-linux-x86_64.tar.bz2 to download the x86 version of PhantomJS 1.9.7 from the command lineto the current working directory.)
  3. Unpack the tarball in your home directory.
    According to https://askubuntu.com/a/25962/168631, the command is tar xjf phantomjs-1.9.7-linux-x86_64.tar.bz2, depending on which version you downloaded.
  4. Create symbolic links to the phantomjs executable in your /bin.
    • Following these instructions, I ran:
      1. sudo ln -s <snip>/<unpacked_tarball>/bin/phantomjs /usr/local/share/phantomjs
      2. sudo ln -s <snip>/<unpacked_tarball>/bin/phantomjs /usr/local/bin/phantomjs
      3. sudo ln -s <snip>/<unpacked_tarball>/bin/phantomjs /usr/bin/phantomjs
like image 27
Kevin Avatar answered Oct 23 '22 22:10

Kevin