Ionic Angular SSR build error: got document is not defined error when try to run SSR build

ReferenceError: document is not defined
    .../dist/app/server/vendor.js:319308:13
    at Module.56601 (.../dist/app/server/vendor.js:319317

dose any one have solution for this error. This error appear when i do SSR build and try to run it.

This error first come from the main.js so i have manually inject document with angular in every pages but now it’s coming from the vendor.js it’s because some of my node modules use document. I want to solution for this.