Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read property 'version' of undefined when rendering on the server #371

Closed
benjamin-albert opened this issue Aug 21, 2018 · 3 comments
Milestone

Comments

@benjamin-albert
Copy link

Bug Report or Feature Request (mark with an x)
- [x] Regression (a behavior that used to work and stopped working in a new release)
- [ ] Bug report -> please search issues before submitting
- [ ] Feature request
- [ ] Documentation issue or request

After updating to 5.1.1 we end up with this error in our server logs when rendering the pdf-viewer component in the server.

ERROR TypeError: Cannot read property 'version' of undefined 
     at new PdfViewerComponent (/app/node_modules/ng2-pdf-viewer/bundles/ng2-pdf-viewer.umd.js:29:70) 
     at createClass (/app/node_modules/@angular/core/bundles/core.umd.js:12519:20) 
     at createDirectiveInstance (/app/node_modules/@angular/core/bundles/core.umd.js:12364:37) 
     at createViewNodes (/app/node_modules/@angular/core/bundles/core.umd.js:13822:53) 
     at Object.createEmbeddedView (/app/node_modules/@angular/core/bundles/core.umd.js:13699:5) 
     at TemplateRef_.createEmbeddedView (/app/node_modules/@angular/core/bundles/core.umd.js:11774:38) 
     at ViewContainerRef_.createEmbeddedView (/app/node_modules/@angular/core/bundles/core.umd.js:11486:52) 
     at NgIf._updateView (/app/node_modules/@angular/common/bundles/common.umd.js:2887:45) 
     at NgIf.set [as ngIf] (/app/node_modules/@angular/common/bundles/common.umd.js:2843:18) 
     at updateProp (/app/node_modules/@angular/core/bundles/core.umd.js:12699:37) 
     at checkAndUpdateDirectiveInline (/app/node_modules/@angular/core/bundles/core.umd.js:12406:19) 
     at checkAndUpdateNodeInline (/app/node_modules/@angular/core/bundles/core.umd.js:13973:20) 
     at checkAndUpdateNode (/app/node_modules/@angular/core/bundles/core.umd.js:13916:16) 
     at prodCheckAndUpdateNode (/app/node_modules/@angular/core/bundles/core.umd.js:14640:5) 
     at Object.eval [as updateDirectives] (ng:///DocumentModule/ReadComponent.ngfactory.js:335:5) 
     at Object.updateDirectives (/app/node_modules/@angular/core/bundles/core.umd.js:14362:29) 
     at checkAndUpdateView (/app/node_modules/@angular/core/bundles/core.umd.js:13882:14) 
     at callViewAction (/app/node_modules/@angular/core/bundles/core.umd.js:14233:21) 
     at execEmbeddedViewsAction (/app/node_modules/@angular/core/bundles/core.umd.js:14191:17) 
     at checkAndUpdateView (/app/node_modules/@angular/core/bundles/core.umd.js:13883:5) 
     at callViewAction (/app/node_modules/@angular/core/bundles/core.umd.js:14233:21) 
     at execComponentViewsAction (/app/node_modules/@angular/core/bundles/core.umd.js:14165:13) 
     at checkAndUpdateView (/app/node_modules/@angular/core/bundles/core.umd.js:13888:5) 
     at callViewAction (/app/node_modules/@angular/core/bundles/core.umd.js:14233:21) 
     at execEmbeddedViewsAction (/app/node_modules/@angular/core/bundles/core.umd.js:14191:17) 
     at checkAndUpdateView (/app/node_modules/@angular/core/bundles/core.umd.js:13883:5) 
     at callViewAction (/app/node_modules/@angular/core/bundles/core.umd.js:14233:21) 
     at execComponentViewsAction (/app/node_modules/@angular/core/bundles/core.umd.js:14165:13) 
     at checkAndUpdateView (/app/node_modules/@angular/core/bundles/core.umd.js:13888:5) 
     at callViewAction (/app/node_modules/@angular/core/bundles/core.umd.js:14233:21) 
     at execEmbeddedViewsAction (/app/node_modules/@angular/core/bundles/core.umd.js:14191:17) 
     at checkAndUpdateView (/app/node_modules/@angular/core/bundles/core.umd.js:13883:5) 
     at callViewAction (/app/node_modules/@angular/core/bundles/core.umd.js:14233:21) 
     at execComponentViewsAction (/app/node_modules/@angular/core/bundles/core.umd.js:14165:13) 
     at Object.checkAndUpdateView (/app/node_modules/@angular/core/bundles/core.umd.js:13888:5) 
     at ViewRef_.detectChanges (/app/node_modules/@angular/core/bundles/core.umd.js:11657:22) 
     at /app/node_modules/@angular/core/bundles/core.umd.js:5956:63 
     at Array.forEach (<anonymous>) 
     at ApplicationRef.tick (/app/node_modules/@angular/core/bundles/core.umd.js:5956:25) 
     at /app/node_modules/@angular/core/bundles/core.umd.js:5789:105 
@benjamin-albert benjamin-albert changed the title Cannot read property 'version' of undefined when rendering in the server Cannot read property 'version' of undefined when rendering on the server Aug 21, 2018
@VadimDez
Copy link
Owner

VadimDez commented Aug 22, 2018

Is there any starter/boilerplate project where I can reproduce this? That would help a lot.

@steambros
Copy link

@VadimDez Looks like PDFJS is undefined when using server side rendering:

let PDFJS: any;
let PDFJSViewer: any;
function isSSR() {
return typeof window === 'undefined';
}
if (!isSSR()) {
PDFJS = require('pdfjs-dist/build/pdf');
PDFJSViewer = require('pdfjs-dist/web/pdf_viewer');
PDFJS.verbosity = PDFJS.VerbosityLevel.ERRORS;
}

So here

private _cMapsUrl = `https://unpkg.com/pdfjs-dist@${ (PDFJS as any).version }/cmaps/`;

PDFJS is undefined and throws an Cannot read property 'version' of undefined error.

VadimDez added a commit that referenced this issue Nov 13, 2018
@VadimDez VadimDez added this to the 5.2.1 milestone Nov 13, 2018
@VadimDez
Copy link
Owner

Fixed in version 5.2.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants