0

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

Domino error

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';

5
  • I don't see why the change from 18 to 19 could cause this. Possible duplicate of stackoverflow.com/questions/38269478 Commented Dec 4, 2024 at 10:01
  • strict : false on tsconfig.json doesn't help.
    – Santosh
    Commented Dec 4, 2024 at 10:18
  • Can you provide a way to reproduce it working on 18? Needs to be debugged. I don't see how it's possible because ng forces the use of native esm for some time, this would prevent legacy libs like domino-ext from being used in 18 too Commented Dec 4, 2024 at 10:52
  • yes my existing project with v18 working fine. Am not sure may be some setting changed while trying to upgrade causing this issue. Is there any alternate for domino or domino-ext ?
    – Santosh
    Commented Dec 5, 2024 at 3:29
  • I'm unaware of it. You need to check first the forks, as they are expected to have the fixes you aim for. Here's the one I saw within few seconds, probably there are others github.com/carlwoodward/domino Commented Dec 5, 2024 at 8:16

0