question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ReferenceError: Document is not defined

See original GitHub issue

I am using angular universal for server side rendering, prior to the upgrade to angular 8 everything was working fine, however after the upgrade, whenever i compile and try to run the server file code, it gives me that Document is not defined error. I’m wondering if you’re directly using the Document object directly somewhere in the library.

... __param(6, core_1.Inject(common_1.DOCUMENT)), __metadata("design:paramtypes", [core_1.ElementRef, core_1.Renderer, lightbox_event_service_1.LightboxEvent, core_1.ElementRef, lightbox_event_service_1.LightboxWindowRef, platform_browser_1.DomSanitizer, Document]) ], LightboxComponent); return LightboxComponent; }()); exports.LightboxComponent = LightboxComponent;

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:33 (19 by maintainers)

github_iconTop GitHub Comments

6reactions
Rlcolli4commented, Sep 4, 2019

@themyth92 I was able to compile my server side rendering code without the error from your node module. It appears that the PR worked in my case. Thanks for hearing us out and getting it out there. @cozzbie Thanks for taking a look at this and getting it handled.

6reactions
aircliffcommented, Jun 11, 2019

@themyth92, below is the error im getting:

`/Users/myfolder/Desktop/apps/myapp/build/server.js:139193 Document]) ^

ReferenceError: Document is not defined at /Users/myfolder/Desktop/apps/myapp/build/server.js:139193:13 at Object…/node_modules/ngx-lightbox/lightbox.component.js (/Users/myfolder/Desktop/apps/myapp/build/server.js:139196:2) at webpack_require (/Users/myfolder/Desktop/apps/myapp/build/server.js:138086:30) at Module…/node_modules/ngx-lightbox/lightbox.component.ngfactory.js (/Users/myfolder/Desktop/apps/myapp/build/server.js:139217:77)`

This is the code when i dig into server.js:139193

LightboxComponent = __decorate([ core_1.Component({ template: "\n <div class=\"lb-outerContainer transition\" #outerContainer>\n <div class=\"lb-container\" #container>\n <img class=\"lb-image\" [src]=\"album[currentImageIndex].src\" class=\"lb-image animation fadeIn\" [hidden]=\"ui.showReloader\" #image>\n <div class=\"lb-nav\" [hidden]=\"!ui.showArrowNav\" #navArrow>\n <a class=\"lb-prev\" [hidden]=\"!ui.showLeftArrow\" (click)=\"prevImage()\" #leftArrow></a>\n <a class=\"lb-next\"[hidden]=\"!ui.showRightArrow\" (click)=\"nextImage()\" #rightArrow></a>\n </div>\n <div class=\"lb-loader\" [hidden]=\"!ui.showReloader\" (click)=\"close($event)\">\n <a class=\"lb-cancel\"></a>\n </div>\n </div>\n </div>\n <div class=\"lb-dataContainer\" [hidden]=\"ui.showReloader\" #dataContainer>\n <div class=\"lb-data\">\n <div class=\"lb-details\">\n <span class=\"lb-caption animation fadeIn\" [hidden]=\"!ui.showCaption\" [innerHtml]=\"album[currentImageIndex].caption\" #caption>\n </span>\n <span class=\"lb-number animation fadeIn\" [hidden]=\"!ui.showPageNumber\" #number>{{ content.pageNumber }}</span>\n </div>\n <div class=\"lb-closeContainer\">\n <a class=\"lb-close\" (click)=\"close($event)\"></a>\n </div>\n </div>\n </div>", selector: '[lb-content]', host: { '(click)': 'close($event)', '[class]': 'ui.classList' } }), __param(6, core_1.Inject(common_1.DOCUMENT)), __metadata("design:paramtypes", [core_1.ElementRef, core_1.Renderer, lightbox_event_service_1.LightboxEvent, core_1.ElementRef, lightbox_event_service_1.LightboxWindowRef, platform_browser_1.DomSanitizer, Document]) ], LightboxComponent); return LightboxComponent; }()); exports.LightboxComponent = LightboxComponent; //# sourceMappingURL=lightbox.component.js.map

This snippet towards the bottom is the line its complaining about (Document):

        platform_browser_1.DomSanitizer,
        Document])
], LightboxComponent);
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to fix ReferenceError: Document is not defined ... - Sabe.io
The most common reason for getting the reference error while on the browser is when you try to access the document object too...
Read more >
ReferenceError: document is not defined in JavaScript
The "ReferenceError: document is not defined" error occurs for multiple reasons: ... The document relates to the document object which represents a web...
Read more >
ReferenceError: document is not defined (in plain JavaScript)
Explanation: The error is caused because NextJs renders the page in the server only and in the server document (document is used inside...
Read more >
How To Fix ReferenceError document is not defined ... - Isotropic
If you are trying to use the document object and receiving a ReferenceError: document is not defined error then there is a good...
Read more >
How to solve the document is not defined error - Flavio Copes
Here's how to fix the “referenceerror: document is not defined” error that you might have in Node.js or with a tool like Next.js....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found