PhantomJS不能使用PDFJS

PhantomJS can't use PDFJS

本文关键字:PDFJS 不能 PhantomJS      更新时间:2023-09-26

我正在编写一个angular应用程序,它使用Mozilla的库PDFJS。不幸的是,当执行应用程序的单元测试时,似乎PhantomJS找不到PDFJS-lib的部分。

错误信息如下:

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

我需要使用PhantomJS,因为我的CI基础设施。

您的问题似乎来自'bind'函数。

如果我没记错,PhantomJS <2.0本身不支持bind,因此会出现"undefined is not a function"消息。您可以使用填充来克服这个问题,参见:

GitHub上的问题:https://github.com/ariya/phantomjs/issues/10522

在NPM上填充:https://www.npmjs.com/package/phantomjs-polyfill

如果你不想使用NPM,也可以从MDN中获得一个polyfill: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind#Polyfill

似乎PhantomJS 2。*现在处理正确,但我还没有尝试。