firebase-tools
firebase-tools copied to clipboard
fix: throw an error when server.ts calls run function
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
runcall inserver.ts- deployment was successful - removed
runcall inserver.ts- deployment was successful server.tshas gotruncall and SSR is enabled inangular.json- an error with guidance was thrownserver.tshas gotruncall and SSR is disabled inangular.json- deployment was successful
Sample Commands
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.