phantomjs执行常见错误

一:在服务器迁移之后发现,phantomjs截图没有执行,但是服务也没有报错(确认phantomjs相关路径没有问题)

二:测试

  1、编写一个测试脚本test.js

console.log('Hello, world!');
phantom.exit();

  2、使用phantomjs执行测试脚本,出现如下错误

[root@VM_4_4_centos opt]# /opt/phantomjs/bin/phantomjs /opt/test.js 
/opt/phantomjs/bin/phantomjs: error while loading shared libraries: libfontconfig.so.1: cannot open shared object file: No such file or directory

三:解决方法

yum -y install freetype

yum -y install fontconfig

  然后执行测试脚本显示正常

[root@VM_4_4_centos opt]# /opt/phantomjs/bin/phantomjs /opt/test.js 
Hello, world!

  

原文地址:https://www.cnblogs.com/ldbangel/p/9761875.html