简体   繁体   English

[TypeError:无法读取未定义的属性“GlobalWorkerOptions”]

[英][TypeError: Cannot read property 'GlobalWorkerOptions' of undefined]

My version of pdfjs-dist: "pdfjs-dist": "^2.4.456" This is import my code:我的 pdfjs-dist 版本: "pdfjs-dist": "^2.4.456"这是导入我的代码:

import PDFJS from 'pdfjs-dist'
import pdfjsWorker from 'pdfjs-dist/build/pdf.worker.entry'

and when I call:当我打电话时:

PDFJS.GlobalWorkerOptions.workerSrc = pdfjsWorker
this.loadingTask = PDFJS.getDocument({ data: self.pdfData })

It return this error: [TypeError: Cannot read property 'GlobalWorkerOptions' of undefined]它返回此错误: [TypeError: Cannot read property 'GlobalWorkerOptions' of undefined]

And I try to console this: PDFJS , it return undefinded我试图安慰这个: PDFJS ,它返回undefinded

So when I try this solution in the internet, I add所以当我在互联网上尝试这个解决方案时,我添加

<script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.5.207/pdf.min.js"></script>

in my index.html and add var PDFJS = window['pdfjs-dist/build/pdf'];在我的index.htmladd var PDFJS = window['pdfjs-dist/build/pdf'];

Then it works perfectly...But I dont know why the first approach doesn't work for me...And I do not want use this from CDN because I think it's not stable for my project.然后它完美地工作......但我不知道为什么第一种方法对我不起作用......而且我不想从 CDN 使用它,因为我认为它对我的项目来说不稳定。 So could you guys give me a point what I missed here?那么你们能告诉我我在这里错过了什么吗? I tried to look around in node-modules to figure out but I still do not why i can't import PDFJS from 'pdfjs-dist' ;我试图在node-modules中四处寻找,但我仍然不明白为什么我不能import PDFJS from 'pdfjs-dist'

I SOLVED MY PROBLEM I do not know if it is the root of problem or not, but I just simple change from import PDFJS from 'pdfjs-dist' to import * as PDFJS from 'pdfjs-dist' , and it work perfectly.我解决了我的问题我不知道这是否是问题的根源,但我只是简单地从import PDFJS from 'pdfjs-dist'更改为import * as PDFJS from 'pdfjs-dist' ,它工作得很好。

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

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