question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

forRoot bug ERROR in Error during template compile of 'AppModule' Function calls are not supported in decorators but 'AuthModule' was called.

See original GitHub issue

version:

    "@angular/cli": "1.6.5",
    "@angular/*i": "^5.2.0"

ng build --prod model

error: ERROR in Error during template compile of ‘AppModule’ Function calls are not supported in decorators but ‘AuthModule’ was called.

    AuthModule.forRoot({
      login_url: `/passport/login`,
      ignores:[
        "passport/login",
        "assets/.*",
        "test.*"
      ]
    })

AuthModule:

@NgModule({
    declarations: [
    ],
    imports: [
    ],
    providers: [

    ],
    exports: [
    ]
})
export class AuthModule {
    public static forRoot(options?:any): ModuleWithProviders {
        if (options && options.ignores && options.ignores.length) {
            /**字符串数组,如果直接写正则会导致angular项目失败,应该是bug */
            options.ignores.map(str => new RegExp(str));
        }
        return {
            ngModule: AuthModule,
            providers: [
                { provide: DA_USER_OPTIONS_TOKEN, useValue: options },
                { provide: DA_OPTIONS_TOKEN, useFactory: optionsFactory, deps: [DA_USER_OPTIONS_TOKEN] },
                { provide: DA_STORE_TOKEN, useClass: LocalStorageStore },
                { provide: DA_SERVICE_TOKEN, useClass: TokenService }
            ]
        };
    }
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:13

github_iconTop GitHub Comments

13reactions
dongjiyancommented, Jan 31, 2018

Unexplained specific reasons You can’t write anything else before return before

export class AuthModule {
    public static forRoot(options?:any): ModuleWithProviders {
        **options.ignores.map(str=>new RegExp(str));**
        return {
            ngModule: AuthModule,
            providers: [
                { provide: DA_USER_OPTIONS_TOKEN, useValue: options },
                { provide: DA_OPTIONS_TOKEN, useFactory: optionsFactory, deps: [DA_USER_OPTIONS_TOKEN] },
                { provide: DA_STORE_TOKEN, useClass: LocalStorageStore },
                { provide: DA_SERVICE_TOKEN, useClass: TokenService }
            ]
        };
    }
}

after

export class AuthModule {
    public static forRoot(options?:any): ModuleWithProviders {
        return {
            ngModule: AuthModule,
            providers: [
                { provide: DA_USER_OPTIONS_TOKEN, useValue: options },
                { provide: DA_OPTIONS_TOKEN, useFactory: optionsFactory, deps: [DA_USER_OPTIONS_TOKEN] },
                { provide: DA_STORE_TOKEN, useClass: LocalStorageStore },
                { provide: DA_SERVICE_TOKEN, useClass: TokenService }
            ]
        };
    }
}
```ts
11reactions
kayvanbreecommented, Feb 9, 2018

@dongjiyan Could you re-open the issue please?

Read more comments on GitHub >

github_iconTop Results From Across the Web

ERROR in Error during template compile of 'AppModule ...
I am getting: ERROR in Error during template compile of 'AppModule' Function calls are not supported in decorators but 'XXXModule' was called. I ......
Read more >
Solving AOT Error in NgRx: Function calls are not supported in ...
ERROR in src/app/app.module.ts(33,25): Error during template compile of 'AppModule' Function calls are not supported in decorators but 'createAction' was ...
Read more >
Angular Modules and NgModule - Complete Guide
An Angular Module is mainly a template compilation context but it also ... lazy loading in AngularJs was not supported directly at the...
Read more >
Building Angular 6 library fails, with a vague error.
BUILD ERROR. Error during template compile of 'Injectable'. Function calls are not supported in decorators but 'ɵmakeDecorator' was called.
Read more >
Calling Function 'Makedecorator' Function Calls Are Not ... - ADocLib
ERROR in Error during template compile of 'AppComponent' Function calls are not supported in decorators but 'beforeMethod' was called in 'log' 'log' calls....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found