angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

The main.server file is not being updated with the Angular 17 schematic update

Open michaeljota opened this issue 2 years ago • 1 comments

Command

update

Is this a regression?

  • [ ] Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

I'm unsure if the "update" schematic should leave the same structure and content as if you are creating a new app with Angular CLI v17, or if this should create a different but consistent state, but neither is happening right now. If you have an Angular v16 app, with the default configuration for nguniversal, and you try to update, the application will be broken.

  • The update will modify the server.ts file with some code that will expect './src/main.server' to export a default function called bootstrap. However, the content of './src/main.server' is not being updated, and neither is another file being created with the expected content.

If you create a new application using the Angular CLI v17 with the option to use ssr, then a './src/main.server' will be created with a default export of a bootstrap function.

You can review the same error being reported in this issue angular/angular#52998, however, in the issue is not mentioned that the default project created with Angular CLI v17 does create the expected file.

Minimal Reproduction

Using CLI

npx -p @angular/cli@16 ng new angular-ssr-migrated
npx ng add @nguniversal/express-engine
git commit -m "chore: add nguniversal"
npx ng update @angular/core@17 @angular/cli@17

Exception or Error

No response

Your Environment

_                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 17.0.5
Node: 20.9.0
Package Manager: npm 10.1.0
OS: win32 x64

Angular: 17.0.5
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, platform-server
... router, ssr

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1700.5 (cli-only)
@angular-devkit/build-angular   17.0.5
@angular-devkit/core            17.0.5 (cli-only)
@angular-devkit/schematics      17.0.5
@schematics/angular             17.0.5
rxjs                            7.8.1
typescript                      5.2.2
zone.js                         0.14.2

Anything else relevant?

Update 12/10/23: After some more code digging, it seems like main.server.ts file should be updated to use a default export.

Update 12/04/23: From the schematic, seems like `isStandalone` is being considered true when evaluated in a migration.
import <% if (isStandalone) { %>bootstrap<% } else { %>AppServerModule<% } %> from './src/main.server';

~~If isStandalone is evaluated as false, then the ./src/main.server.ts file shouldn't be updated.~~

Even if isStandalone is evaluated as false, the ./src/main.server.ts file should be updated to use a default export.

Original:

I guess the correct content of the './src/main.server' file should be:

import { AppServerModule } from './app/app.server.module';

export default AppServerModule;

Considering this don't want to do too many updates to the code.

michaeljota avatar Dec 04 '23 00:12 michaeljota

Updated the issue with information I found in the template file. I'm not investigating this, however, I'm reviewing the code, so I might find something relevant.

michaeljota avatar Dec 04 '23 13:12 michaeljota

Closed via https://github.com/angular/angular-cli/pull/27493

alan-agius4 avatar Apr 18 '24 14:04 alan-agius4

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.