abp icon indicating copy to clipboard operation
abp copied to clipboard

Angular: ReferenceError: document is not defined

Open realZhangChi opened this issue 3 years ago • 5 comments

I want to use Angular Universal for server side rendering for abp's angular project, I set it up according to the official angular documentation and then I solved the localstorage problem according to an answer on StackOverflow.

Running yarn dev:ssr and opening the page, I get the error message(some paths are replaced with ***):

ReferenceError: document is not defined
    at Object.AppendToHead (***\dist\***\server\main.js:101810:28)
    at Object.AppendStyleToHead (***\dist\***\server\main.js:102399:59)
    at Object.factory (***\dist\***\server\main.js:109658:91)
    at R3Injector.hydrate (***\dist\***\server\main.js:161018:35)
    at R3Injector.get (***\dist\***\server\main.js:160834:33)
    at injectInjectorOnly (***\dist\***\server\main.js:154324:33)
    at ɵɵinject (***\dist\***\server\main.js:154328:61)
    at injectArgs (***\dist\***\server\main.js:154408:23)
    at Object.factory (***\dist\***\server\main.js:161109:52)
    at R3Injector.hydrate (***\***\server\main.js:161018:35)
...

After checking the dist***\server\main.js file, I guessed that this problem might be caused by using the document element in DOM_STRATEGY.

Any help is appreciated. Thanks.

realZhangChi avatar Feb 28 '22 06:02 realZhangChi

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Apr 29 '22 21:04 stale[bot]

ping?

realZhangChi avatar May 06 '22 06:05 realZhangChi

A slight bump, this made angular universal unusable.

hillin avatar Jun 13 '22 10:06 hillin

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Aug 12 '22 23:08 stale[bot]

Hi, @muhammedaltug @EngincanV Any suggestions for using Angular Universal?

realZhangChi avatar Sep 01 '22 02:09 realZhangChi