Repository: ng-packagr/ng-packagr

Issue #1428: "Function calls are not supported in decorators but 'RoutingService' was called" - while ng build --prod
Created: 2019-10-22T10:38:23Z
When I am trying to build using 'ng build' it works properly. When I do 'ng build --prod', I end up with below error :
ERROR in Error during template compile of 'MainRoutingModule'
Function calls are not supported in decorators but 'RoutingService' was called.
RoutingService is a service used to get path based on Id and getById is a static method.
main-routing.module.ts
_import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { MainComponent } from './main.component';
import { AuthService } from './authorization/auth.service';
import { RoutingService } from '../shared/routing/routing.service';
import { DashboardComponent } from '../dashboard/dashboard.component';
const routes: Routes = [
{
path: RoutingService.getById('main', 'path'),
component: MainComponent,
children: [
{
path: '',
redirectTo: RoutingService.getById('home', 'path'),
pathMatch: 'full',
data: {
breadcrumbItem: {
ignore: true
}
}
},
{
path: RoutingService.getById('home', 'path'),
component: DashboardComponent,
data: {
breadcrumbItem: {
label: 'home'
}
}
},
{
path: RoutingService.getById('dashboard', 'path'),
redirectTo: RoutingService.getById('home', 'path'),
pathMatch: 'full',
data: {
breadcrumbItem: {
ignore: true
}
}
},
{
path: RoutingService.getById('projects', 'path'),
canActivate: [AuthService],
loadChildren: '../project/project.module#ProjectModule'
},
{
path: RoutingService.getById('campaigns', 'path'),
canActivate: [AuthService],
loadChildren: '../campaign/campaign.module#CampaignModule'
},
{
path: RoutingService.getById('vehicles', 'path'),
canActivate: [AuthService],
loadChildren: '../vehicle/vehicle.module#VehicleModule'
}
]
}
];
@NgModule({
imports: [RouterModule.forRoot(routes, {
// => should load page even if URL has not changed (solves problem that earlier filled input fields stay filled on reload)
onSameUrlNavigation: 'reload'
})],
exports: [RouterModule]
})
export class MainRoutingModule { }_

Duplicate issue #885: "Function calls are not supported in decorators" when consuming library built with ng-packagr
Created: 2018-05-18T20:48:58Z
Type of Issue
[X] Bug Report
[ ] Feature Request

Description
I'm using ng-packagr via Angular CLI to create a library. The library builds successfully. When I try to consume this library from another Angular application, though, I get the error "function calls are not supported in decorators".
I have a module in my library, LoggerModule, that has a static forModule method:
@NgModule({})
export class LoggerModule {
  static forModule(module?: string): ModuleWithProviders {
    return {
      ngModule: LoggerModule,
      providers: [
        Store,
        { provide: MODULE_TOKEN, useValue: module },
        { provide: LoggerService, useFactory: LoggerServiceFactory, deps: [Store, MODULE_TOKEN] }
      ]
    };
  }
}

In my application, in the AppModule, I am calling LoggerModule.forModule:
@NgModule({
  declarations: [AppComponent],
  imports: [
    // ...
    LoggerModule.forModule('AppModule')
  ]

When I do a normal ng build, everything builds and runs fine. But if I do a ng build --aot, I get this error:
ERROR in Error during template compile of 'AppModule'
  Function calls are not supported in decorators but 'LoggerModule' was called.

I have a separate version of this library that's not built with ng-packagr, but rather just compiled in along with the main app, and even an AOT build is successful in that setup.
How To Reproduce

Create a module in the library with a static method
Build the module with ng-packagr
Try to consume the package in an app, calling that static method in the AppModule's imports array

Expected Behaviour
This error isn't raised and the build continues.
Version Information
$ node_modules/.bin/ng-packagr --version
ng-packagr: 3.0.0-rc.5
@angular/compiler: 6.0.2
rollup: 0.58.2
tsickle: 0.28.0
typescript: 2.7.2
rxjs: 6.1.0
node: 9.11.1
yarn 1.6.0

Please include all version numbers that might be relevant, e.g. third-party libraries

Closing comment (2019-10-28T05:00:53Z): Duplicate of #1428