Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

9kubczas4
Copy link
Contributor

@9kubczas4 9kubczas4 commented Apr 9, 2024

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: #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 9kubczas4 force-pushed the pawelkubiak_throw_an_error_when_run_is_called_for_ng_ssr_17 branch from 1172fd8 to b6fdea3 Compare April 9, 2024 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants