I encountered an issue while building a Progressive Web App (PWA) from my Angular application. When running ng build --prod
, I received the following error:
ERROR in app\app.module.ts(108,64): Error during template compile of 'AppModule'
Function calls are not supported in decorators but 'Environment' was called in 'environment'
'environment' calls 'Environment'.
The error seemed confusing as I had already added export
to the class, which is evident from the code snippet below:
environment.prod.ts
import { BaseEnvironment } from './base-environment';
import { ProspectBuilderModel } from '../app/models/prospect';
export class Environment extends BaseEnvironment {
production: boolean = true;
prospectBuilderModel: ProspectBuilderModel = {
buildQuote: false,
// other properties...
};
}
export const environment = new Environment();
base-environment.ts
import { ProspectBuilderModel } from '../app/models/prospect';
export abstract class BaseEnvironment {
abstract production: boolean;
abstract prospectBuilderModel: ProspectBuilderModel;
}
app.module.ts
...
],
imports: [
BrowserModule,
AppRoutingModule,
FormsModule,
MultiselectDropdownModule,
ReactiveFormsModule,
HttpModule,
ToastrModule.forRoot(),
BrowserAnimationsModule,
NgxMyDatePickerModule.forRoot(),
PopoverModule.forRoot(),
ModalModule.forRoot(),
ServiceWorkerModule.register('/ngsw-worker.js', { enabled: environment.production })
],
providers: [
...
If anyone has ideas on how to resolve this error, please let me know.