简体   繁体   English

PhantomJS不能使用PDFJS

[英]PhantomJS can't use PDFJS

I am writing an angular-app, that uses Mozilla's library PDFJS . 我正在编写一个使用Mozilla的库PDFJS的angular-app。 Unfortunately, when executing the unit-tests of the application, it seems that PhantomJS can't find parts of the PDFJS-lib. 不幸的是,在执行应用程序的单元测试时,PhantomJS似乎找不到PDFJS-lib的一部分。

Here is the error message: 这是错误消息:

PhantomJS 1.9.8 (Linux 0.0.0) ERROR
TypeError: 'undefined' is not a function (near '...}.bind(this), REJECTION_TI...')
at /home/[...]/bower_components/pdfjs-dist/build/pdf.js:1222

I need to use PhantomJS because of my CI infrastructure. 由于我的CI基础架构,我需要使用PhantomJS。

Your problem seems to come from the 'bind' function. 您的问题似乎来自“绑定”功能。

If I remember correctly, PhantomJS < 2.0 doesn't support bind natively, hence the 'undefined is not a function' message. 如果我没记错的话,PhantomJS <2.0不支持本地绑定,因此“未定义不是函数”消息。 You can use a polyfill to overcome this problem, see: 您可以使用polyfill来解决此问题,请参阅:

Issue on GitHub: https://github.com/ariya/phantomjs/issues/10522 在GitHub上发布: https : //github.com/ariya/phantomjs/issues/10522

Polyfill on NPM : https://www.npmjs.com/package/phantomjs-polyfill NPM上的Polyfill: https ://www.npmjs.com/package/phantomjs-polyfill

If you don't want to use NPM, there is a polyfill also available from the MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind#Polyfill 如果您不想使用NPM,则可以从MDN获得一个polyfill: https : //developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind#Polyfill

It also seems that PhantomJS 2.* now handles it correctly, but I haven't tried. 似乎PhantomJS 2. *现在可以正确处理它,但我没有尝试过。

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

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