Skip to content
Advertisement

Angular: Is there any need to use app.server.module.ts anymore?

I am currently transforming an old Angular app to a new version (Angular 10) and there is a file in app folder called app.server.module.ts. However, asa far as I see, it seemsto be related to old versions (maybe AngularJS), but I am not sure how to remove this file (which changes should I made in app.module.ts, app.routing.module.ts, etc. Here is that file below:

app.server.module.ts

import { NgModule } from '@angular/core';
import { ServerModule } from '@angular/platform-server';
import { ModuleMapLoaderModule } from '@nguniversal/module-map-ngfactory-loader';
import { AppComponent } from './app.component';
import { AppModule } from './app.module';

@NgModule({
    imports: [AppModule, ServerModule, ModuleMapLoaderModule],
    bootstrap: [AppComponent]
})
export class AppServerModule { }

Will it be a problem to remove completely?

Update: Here is the only file using this module in the entire frontend project:

tsconfig.server.json.ts:

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "target": "es2016"
  },
  "angularCompilerOptions": {
    "entryModule": "app/app.server.module#AppServerModule"
  }
,
  "files": [
    "main.ts"
  ],
  "include": [
    "src/**/*.d.ts"
  ]
}

Advertisement

Answer

It’s not related to AngularJS but to Angular.

If you want to remove this file (without knowing the whole context of your application), you would at least need to make two changes :

Add the bootstrap metadata into another module (AppModule ?) as it defines the root component of your app being bootstrapped from your index.html

bootstrap: [AppComponent]

Check your main.ts file as it might be the module used to bootstrap your application :

platformBrowserDynamic()
  .bootstrapModule(AppServerModule)
  .catch((err) => console.error(err));

If removing this module in benefit of your AppModule, you would as well need to add the imports ServerModule and ModuleMapLoaderModule into its medatdata.

Advertisement