简体   繁体   English

无法在Rails应用程序中连接PhantomJS和Poltergeist

[英]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. 我已按照Poltergeist github页面上的说明操作,但我一直收到错误信息,表明我的PhantomJS版本错误。

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. 现在,我已经下载了phantomjs v1.8.1(以及后来的v1.9.2),因此版本是正确的。 This is really driving me crazy. 这真让我疯狂。 I use Ubuntu 13.04, but I doubt that's the reason. 我使用Ubuntu 13.04,但我怀疑这是原因。

Googling for the error returns nothing of use. 谷歌搜索错误返回没有任何用处。

Any ideas? 有任何想法吗?

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. 我发现非常奇怪的是,错误报告了phantomjs版本为“50”,这是不可能的。

I've tracked the error down to the "cliver" gem, a gem that detects versions of installed programs. 我已将错误跟踪到“cliver”gem,这是一个检测已安装程序版本的gem。 It does so by regex matching the desired version string to the result of 它通过正则表达式匹配所需的版本字符串到结果

 {command} -v

Now, when I run phantomjs -vi get "1.8.1", so what was happening? 现在,当我运行phantomjs -vi得到“1.8.1”时,发生了什么? On closer inspection "1.8.1" wasn't all that I was getting back! 仔细观察“1.8.1”并不是我回来的全部! 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". 我有一个fontconf错误,果然,它包含的第一个数字是“50”。 Cliver matches against standard output, so it couldn't get a proper version because the system was writing errors out. Cliver与标准输出匹配,因此无法获得正确的版本,因为系统正在编写错误。

Once I reconfigured the 50-user.conf not to use line 9, the error was gone and poltergeist started working as expected. 一旦我重新配置50-user.conf不使用第9行,错误就消失了,并且poltergeist开始按预期工作。

In my case, using apt-get to install PhantomJS was installing an older version of PhantomJS. 在我的例子中,使用apt-get安装PhantomJS是安装较旧版本的PhantomJS。 I had to manually install PhantomJS by downloading the tarball, unpacking it, and creating links to the executable in /bin : 我不得不通过下载tarball,解压缩并在/bin创建可执行文件的链接来手动安装PhantomJS:

  1. If you haven't already, remove the outdated version of PhantomJS you have installed. 如果您还没有,请删除已安装的过期版本的PhantomJS。
    Using apt-get , the command for me was sudo apt-get remove phantomjs . 使用apt-get ,对我来说命令是sudo apt-get remove phantomjs
  2. Download the tarball from http://phantomjs.org/download.html . http://phantomjs.org/download.html下载tarball。
    (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.) (例如,你可以使用wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.7-linux-x86_64.tar.bz2从命令行下载x86版本的PhantomJS 1.9.7当前的工作目录。)
  3. Unpack the tarball in your home directory. 将tarball解压缩到您的主目录中。
    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. 根据https://askubuntu.com/a/25962/168631 ,该命令是tar xjf phantomjs-1.9.7-linux-x86_64.tar.bz2 ,具体取决于您下载的版本。
  4. Create symbolic links to the phantomjs executable in your /bin . 创建/bin phantomjs可执行文件的符号链接。
    • 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

i also faced the same issue and resolved it by using the phantomjs gem ,which will install the phantomjs based on the platform you are working. 我也遇到了同样的问题并通过使用phantomjs gem来解决它,它将根据你正在使用的平台安装phantomjs。

first remove the platform specific phantomjs ,so if you are using ubuntu sudo apt-get --purge remove phantomjs sudo rm /usr/bin/phantomjs sudo ln -s /node_modules/phantomjs/lib/phantom/bin/phantomjs /usr/bin/phantomjs 首先删除平台特定的phantomjs,所以如果你使用ubuntu sudo apt-get --purge remove phantomjs sudo rm /usr/bin/phantomjs sudo ln -s /node_modules/phantomjs/lib/phantom/bin/phantomjs /usr/bin/phantomjs

尝试将phantomjs移动到/bin目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM