firebase-tools icon indicating copy to clipboard operation
firebase-tools copied to clipboard

fix: throw an error when server.ts calls run function

Open 9kubczas4 opened this issue 1 year ago • 1 comments

Description

There was a following change in main server file template in Angular 17:

// 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();
}

to

run();

The guard to call run function was removed. In the result there is an issue when someone tries to deploy Angular 17+ app with SSR.

I've added a check in the deployment script, if run function is called in server.ts then error with message: For SSR to work properly, please remove the runfunction call from theserver.ts file. will be thrown.

The solution will provide better guidance to resolve this issue: https://github.com/firebase/firebase-tools/issues/6651.

Scenarios Tested

Angular 17+:

  • commented out run call in server.ts - deployment was successful
  • removed run call in server.ts - deployment was successful
  • server.ts has got run call and SSR is enabled in angular.json - an error with guidance was thrown
  • server.ts has got run call and SSR is disabled in angular.json - deployment was successful

Sample Commands

9kubczas4 avatar Apr 09 '24 17:04 9kubczas4

Hi @jamesdaniels,

What do you think about this change? It could help with problem mentioned in this issue: https://github.com/firebase/firebase-tools/issues/6651.

When server.ts will contain run() call then meaningful error will be thrown.

9kubczas4 avatar Jun 05 '24 12:06 9kubczas4