Skip to content

ivy-ngcc is unable to recognise AngularFireModule.initializeApp as ModuleWithProviders #29078

Closed

Description

@sarunint

🐞 bug report

Affected Package

The issue is caused by package @angular/compiler-cli

Is this a regression?

No

Description

Take a look at this code (taken from https://unpkg.com/@angular/fire@5.1.1/es2015/firebase.app.module.js):

let AngularFireModule = AngularFireModule_1 = class AngularFireModule {
    static initializeApp(options, nameOrConfig) {
        return {
            ngModule: AngularFireModule_1,
            providers: [
                { provide: FirebaseOptionsToken, useValue: options },
                { provide: FirebaseNameOrConfigToken, useValue: nameOrConfig }
            ]
        };
    }
};
AngularFireModule = AngularFireModule_1 = __decorate([
    NgModule({
        providers: [FirebaseAppProvider],
    })
], AngularFireModule);
export { AngularFireModule };

ivy-ngcc cannot recognise the AngularFireModule.initializeApp and mark it as ModuleWithProviders.

This is because the current implementation of ivy-ngcc which looks for ts.ClassDeclaration. Instead, the code above is a variable assignment to ts.BinaryExpression which includes ts.ClassExpression.

There are 2 solutions to this issue:

  1. Make ivy-ngcc to able to recognise class declaration like this.
  2. Tell library authors to use angularCompilerOptions.annotationsAs as static fields during packaging.

My voice is with solution 2, though.

🔬 Minimal Reproduction

N/A

🔥 Exception or Error

N/A

🌍 Your Environment

Angular Version:



8.0.0-beta.6

Anything else relevant?

This causes #28603.

Activity

  1. added this to the needsTriage milestone on Mar 2, 2019
  2. StephenFluin commented on Mar 3, 2019

    @StephenFluin
    Contributor

    For future search reference, the symptom I'm seeing that I believe is caused by this is the error:
    Error: Value at position 4 in imports array is not a reference: [object Object] with position depending on where you have the ModuleWithProviders in the import array.

  3. sarunint commented on Mar 3, 2019

    @sarunint
    ContributorAuthor

    @StephenFluin That's the exact error message that makes me go through debugging the ivy-ngcc.

    By the way, what's the intended solution for this: fix ivy-ngcc or fix the library?

  4. petebacondarwin commented on Mar 4, 2019

    @petebacondarwin
    Contributor

    The fix needs to be in the ngcc tool.

  5. added a commit that references this issue on Apr 2, 2019
    901708b
  6. added a commit that references this issue on Apr 17, 2019
    a84e8b4
  7. angular-automatic-lock-bot commented on Sep 14, 2019

    @angular-automatic-lock-bot

    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.

  8. locked and limited conversation to collaborators on Sep 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions