Open jz1494 opened 3 months ago
Getting Windows undefined with using Angular11 server side rendering
Also getting TypeError: Cannot read property 'polyfillWrapFlushCallback' of undefined
Another one is TypeError: Cannot redefine property: constructor
Is there any solution for this?
Here si my server.ts
import 'zone.js/dist/zone-node'; import { ngExpressEngine } from '@nguniversal/express-engine'; import * as express from 'express'; import { join } from 'path'; import 'node-self'; const domino = require('domino'); // const fs = require('fs'); import * as fs from 'fs'; // import { existsSync } from 'fs'; // import * as domino from 'domino'; // const template = fs.readFileSync(path.join(distFolder, 'index.html')).toString(); // Shim for the global window and document objects. const distFolder = join(process.cwd(), 'dist/browser'); const indexHtml = fs.existsSync(join(distFolder, 'index.original.html')) ? 'index.original.html' : 'index'; // const template = fs.readFileSync(join(distFolder, indexHtml)).toString(); const win = domino.createWindow(indexHtml); // console.log('Win==>',win); global['window'] = win; // global['self'] = win; global['document'] = win.document; global['HTMLElement'] = win.HTMLElement; global['navigator'] = win.navigator; import { AppServerModule } from './src/main.server'; import { APP_BASE_HREF } from '@angular/common'; // The Express app is exported so that it can be used by serverless Functions. export function app(): express.Express { const server = express(); console.log('server side'); const path = require('path'); // Our Universal express-engine (found @ https://github.com/angular/universal/tree/master/modules/express-engine) server.engine('html', ngExpressEngine({ bootstrap: AppServerModule, })); server.set('view engine', 'html'); server.set('views', distFolder); // Example Express Rest API endpoints // server.get('/api/**', (req, res) => { }); // Serve static files from /browser server.get('*.*', express.static(distFolder, { maxAge: '1y' })); /* server.get('*', function (req, res) { res.sendFile(join(distFolder, 'browser', 'index.html')); }); */ // All regular routes use the Universal engine server.get('*', (req, res) => { res.render(indexHtml, { req, providers: [{ provide: APP_BASE_HREF, useValue: req.baseUrl }] }); }); return server; }
Polymer.version : 3.4.1 Angular version : 11 webcomponents : 2.5.0
Getting Windows undefined with using Angular11 server side rendering
Also getting TypeError: Cannot read property 'polyfillWrapFlushCallback' of undefined![Screenshot (292)](https://github.com/Polymer/polymer/assets/153794829/130dc039-6e68-41f0-acbb-46a80c78be2b)
Another one is TypeError: Cannot redefine property: constructor![Screenshot-293-](https://github.com/Polymer/polymer/assets/153794829/6f1c0ae1-0d2b-4fec-951e-1c3801c2aac5)
Is there any solution for this?
Here si my server.ts
Versions
Polymer.version : 3.4.1 Angular version : 11 webcomponents : 2.5.0