I am trying to update my angular version from 18 to 19.0.1
Domino library causing issue and angular not able to compile. I have domino-ext
in my server.ts
My server.ts
import 'zone.js/node';
import { enableProdMode } from "@angular/core";
(global as any).WebSocket = require('ws');
(global as any).XMLHttpRequest = require('xhr2');
// import 'zone.js/dist/zone-node';
const domino = require('domino-ext');
const fs = require('fs');
const path = require('path');
import { CommonEngine } from '@angular/ssr/node';
import * as express from 'express';
import { existsSync } from 'node:fs';
import { join } from 'node:path';
const dotenv = require('dotenv');
dotenv.config();
const distFolder = join(process.cwd(), 'dist/ss/browser');
const template = fs.readFileSync(path.join(distFolder, 'index.html')).toString();
const win = domino.createWindow(template.toString());
global['window'] = win;
global['document'] = win.document;
global['DOMTokenList'] = win.DOMTokenList;
global['Node'] = win.Node;
global['Text'] = win.Text;
global['HTMLElement'] = win.HTMLElement;
global['navigator'] = win.navigator;
global['getComputedStyle'] = win.getComputedStyle;
// The Express app is exported so that it can be used by serverless Functions.
enableProdMode();
import AppServerModule from './main.server';
import { APP_BASE_HREF } from '@angular/common';
export function app(): express.Express {
const server = express();
const distFolder = join(process.cwd(), 'dist/ss/browser');
const indexHtml = existsSync(join(distFolder, 'index.original.html'))
? join(distFolder, 'index.original.html')
: join(distFolder, 'index.html');
const commonEngine = new CommonEngine();
server.set('view engine', 'html');
server.set('views', distFolder);
// Example Express Rest API endpoints
// server.get('/api/**', (req, res) => { });
// Serve static files from /browser
const cors = require('cors');
const corsOptions = {
origin: ['https://*.example.com', 'https://example.com', "localhost:4200"], // Whitelist your domains
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
credentials: true, // Include cookies for authentication
};
server.use(cors(corsOptions));
server.get('*.*', express.static(distFolder, {
maxAge: '1y'
}));
let routesPath = ['/invite', 'login', '/invite/**','/lm', '/dashboard', '/dashboard/**', '/public/**', '/public', '/pre'];
server.get(routesPath, (req, res) => {
// console.log(req);
res.sendFile(distFolder + '/index.html');
});
// All regular routes use the Angular engine
server.get('*', (req, res, next) => {
const { protocol, originalUrl, baseUrl, headers } = req;
commonEngine
.render({
bootstrap : AppServerModule,
documentFilePath: indexHtml,
url: `${protocol}://${headers.host}${originalUrl}`,
publicPath: distFolder,
providers: [
{ provide: APP_BASE_HREF, useValue: baseUrl },
{ provide: 'customConfig', useValue: req.get('host') }
],
})
.then((html) => res.send(html))
.catch((err) => next(err));
});
return server;
}
function run(): void {
const port = process.env['PORT'] || 8000;
// Start up the Node server
const server = app();
server.listen(port, () => {
console.log(`Node Express server listening on http://localhost:${port}`);
});
}
// Webpack will replace 'require' with '__webpack_require__'
// '__non_webpack_require__' is a proxy to Node 'require'
// The below code is to ensure that the server is run only when not requiring the bundle.
declare const __non_webpack_require__: NodeRequire;
const mainModule = __non_webpack_require__.main;
const moduleFilename = mainModule && mainModule.filename || '';
if (moduleFilename === __filename || moduleFilename.includes('iisnode')) {
run();
}
export * from './main.server';
strict : false
on tsconfig.json doesn't help.