ERROR in Error encountered resolving symbol values statically WITH functions exported.
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
Same problem here, if I'll provide third party providers or modules, e.g.:
useFactory: isProduction => new LogService(isProduction)
ERROR in Error encountered resolving symbol values statically.
Function calls are not supported. Consider replacing the function or lambda
with a reference to an exported function (position 42:19 in the original .ts file),
resolving symbol AppModule in /Users/serhiisol/Development/admin-app/src/app/app.module.ts
log points on beginning of arrow function, e.g. on isProduction.
@laPlacek hmmm nothing you have shown looks incorrect. Could you share how you are importing AuthModule? or even better would be be possible for you to do reproduce in a minimal repo and share?
@serhiisol your specific issue is that you need to you change your code from what you currently have to:
export function logServiceFactory(isProduction) {
return new LogService(isProduction)
}
and then
useFactory: logServiceFactory
@deebloo that's one of the examples, basically the problem is in AOT and Angular analyzer. It analyzes code in all cases whether you wanted to have aot or not.
@serhiisol correct even if you don't use AOT your code needs to be statically analyzable
that's bad, it should be optional, should have some flag not to use this aot and analysis, IMHO, a lot of libraries, projects do not support AoT, what they should do in that case? rewrite application entirely ? I doubt
There are other discussions going on about that particular issue, eventually AOT will be the default way angular apps are built. AOT does not require entire rewrites, it just requires the code in your decorators be statically analyzable
What about 3rd parties, which component/module will import? Will the analyzer analyze them ?
@serhiisol only angular libraries. Jquery/moment and other 3rd part libs don't need to do anything special
@deebloo so if library won't support AOT you stuck
@serhiisol at least as of now yes. Is there a certain library you are having trouble with?
only angular :) this AOT stuff just do not work correctly, always throws errors even if I exactly doing everything from the manual it still throws errors
can you post some reproducible examples? The only problem with what you posted before was using inline functions for your factories. This may not be the correct forum for that troubleshooting however. I would be happy to help you trouble shoot
currently it throws error
ERROR in SVGIconModule is not an NgModule
and the module itself looks like:
import { NgModule } from '@angular/core';
import { SVGComponent } from './svg-icon.component';
@NgModule({
declarations: [
SVGComponent
],
imports: [
],
exports: [SVGComponent],
})
export class SVGIconModule { }
import without wildcard, from my custom 3rd party from node_modules, e.g. so:
import { SVGIconModule, SVGService } from 'ng-components/svg-icon';
@serhiisol can you provide more context? How and where SVGIconModule is used? is that module in the same project as the main app?
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { SVGIconModule, SVGService } from 'ng-components/svg-icon';
import { AppComponent } from './app.component';
import { routing } from './app.routing';
@NgModule({
imports: [
BrowserModule,
CommonModule,
SVGIconModule,
routing
],
providers: [
SVGService
],
declarations: [ AppComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule {
constructor(svgService: SVGService) {
svgService.path = './assets/svg';
}
}
Is your library published somewhere or are you using a linked library
I have another folder and npm installs this package from the folder. And yes, I'm linking them together. But issue appears also without linking.
package.json:
"ng-components": "file:../ng-components"
I don't think that will work. Your issue isn't tied to AOT I think there is an active bug using external libraries not standardly installed
that's not correct, at the end, ng-components just a normal package inside node_modules, with one folder, e.g. in this case svg-icon, and then import it normally like normal package
I've got the same issue after updating dependencies two hours ago, with the npm package "angular-oauth2-oidc"...