angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

ERROR in Error encountered resolving symbol values statically WITH functions exported.

Open laPlacek opened this issue 9 years ago • 33 comments

OS?

W10

Versions.

angular-cli: 1.0.0-beta.24 node: 6.9.4 os: win32 x64 @angular/common: 2.4.3 @angular/compiler: 2.4.3 @angular/core: 2.4.3 @angular/forms: 2.4.3 @angular/http: 2.4.3 @angular/platform-browser: 2.4.3 @angular/platform-browser-dynamic: 2.4.3 @angular/platform-server: 2.4.3 @angular/router: 3.4.3 @angular/compiler-cli: 2.4.3

Repro steps.

Consider following module:

export function angularHttpFactory(backend: XHRBackend, defaultOptions: RequestOptions): Http {
  return new Http(backend, defaultOptions);
}

export function authHttpFactory(auth: Auth, backend: XHRBackend, defaultOptions: RequestOptions): AuthHttp {
  return new AuthHttp(auth, backend, defaultOptions);
}

@NgModule({
  declarations: [LoginLoaderComponent],
  imports: [CommonModule, HttpModule, Ng2Webstorage],
  exports: [LoginLoaderComponent]
})
export class AuthModule {
  static forRoot(authConfig: AuthConfig): ModuleWithProviders {
    return {
      ngModule: AuthModule,
      providers: [
        { provide: AUTH_CONFIG, useValue: authConfig },
        { provide: ANGULAR_HTTP, useFactory: angularHttpFactory, deps: [XHRBackend, RequestOptions] },
        Auth,
        { provide: Http, useFactory: authHttpFactory , deps: [Auth, XHRBackend, RequestOptions] },
        AuthUser
      ]
    };
  }

  static forChild(): ModuleWithProviders {
    return {
      ngModule: AuthModule
    };
  }
}

The log given by the failure.

ERROR in Error encountered resolving symbol values statically. Calling function 'AuthModule', function calls are not supported. Consider replacing the function or lambda with a reference to an exported function, resolving symbol AppModule in C:/Users/jacek_dauth3h/Documents/dev/action-center-web-app/src/app/app.module.ts, resolving symbol AppModule in C:/Users/jacek_dauth3h/Documents/dev/action-center-web-app/src/app/app.module.ts

laPlacek avatar Jan 12 '17 13:01 laPlacek

@serhiisol the error of "ERROR in SVGIconModule is not an NgModule" is not tied to the problem stated in this issue. Id suggest looking through the other issues and if you can't find it create a new one

deebloo avatar Jan 13 '17 14:01 deebloo

it's actually produced by the same code analyzer

serhiisol avatar Jan 13 '17 14:01 serhiisol

@serhiisol it is, but the subject of this issues says explicitly what it is about. it is not about all problems related to code analyzer, but about the specific problem: resolving symbol values statically WITH functions exported.

@deebloo it turns out, the same issue occurs when using aot compiler without angular CLI. saying that i'm going to continue the discussion on https://github.com/angular/angular/issues/13892

Thanks for help, i cannot make the repo or the used packages public since they are property of the client.

laPlacek avatar Jan 13 '17 16:01 laPlacek

No worries. Hope you get it worked out!

deebloo avatar Jan 13 '17 16:01 deebloo

@laPlacek these errors produced by analyzer, look at the code of aot compiler in @angular/compiler

serhiisol avatar Jan 13 '17 17:01 serhiisol

Closing as the (original) issue seems to be a static analysis one as per https://github.com/angular/angular-cli/issues/3967#issuecomment-272480733.

filipesilva avatar Jan 24 '17 16:01 filipesilva

@filipesilva could you explain how to disable static analysis without AOT? My App code is not ready for AOT and CLI fails to compile it despite the fact that I didn't turn on AOT

serhiisol avatar Jan 24 '17 16:01 serhiisol

@serhiisol there is no way to disable it currently. Static analysis is always performed on the code.

filipesilva avatar Jan 24 '17 16:01 filipesilva

@filipesilva In angular team, did you even planned to give that option? just for curiosity

serhiisol avatar Jan 24 '17 16:01 serhiisol

There's no plans to add that option in the CLI that I know of. @hansl can you weigh in?

filipesilva avatar Jan 24 '17 16:01 filipesilva

The Angular documentation still actively promotes the use of static methods in decorators, so no surprise it's so widely used. Is there a (simple) work-around to import ModuleWithProviders into application modules (or modules in general)?

https://angular.io/docs/ts/latest/guide/ngmodule.html#!#core-for-root

ghost avatar Mar 23 '17 02:03 ghost

@Cogitaria you're right. If that approach has problems with AOT we shouldn't be promoting it in the docs.

filipesilva avatar Mar 26 '17 20:03 filipesilva

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.