Ngc error due to resolving symbol values statically (rc0)

I followed the upgrade steps in the changelog to convert my existing project to rc0.

When I run ionic-app-scripts build or ngc (or anything that directly triggers that command), I get the following error:

[08:50:01]  ngc error: Error: Error encountered resolving symbol values statically. Function calls are not supported. Consider replacing the function or lambda with a reference to an exported function, resolving symbol AppRootToken in C:/Project/node_modules/ionic-angular/components/app/app-root.d.ts, resolving symbol IonicModule in C:/Project/node_modules/ionic-angular/module.d.ts, resolving symbol AppModule in C:/Project/.tmp/app/app.module.ts, resolving symbol AppModule in C:/Project/.tmp/app/app.module.ts
    at simplifyInContext (C:\Project\node_modules\@angular\compiler-cli\src\static_reflector.js:469:23)
    at StaticReflector.simplify (C:\Project\node_modules\@angular\compiler-cli\src\static_reflector.js:472:22)
    at StaticReflector.annotations (C:\Project\node_modules\@angular\compiler-cli\src\static_reflector.js:61:36)
    at _loop_1 (C:\Project\node_modules\@angular\compiler-cli\src\codegen.js:53:54)
    at CodeGenerator.readFileMetadata (C:\Project\node_modules\@angular\compiler-cli\src\codegen.js:66:13)
    at C:\Project\node_modules\@angular\compiler-cli\src\codegen.js:100:74
    at Array.map (native)
    at CodeGenerator.codegen (C:\Project\node_modules\@angular\compiler-cli\src\codegen.js:100:35)
    at codegen (C:\Project\node_modules\@angular\compiler-cli\src\main.js:7:81)
    at Object.main (C:\Project\node_modules\@angular\tsc-wrapped\src\main.js:30:16)

[08:50:01]  ngc error: Compilation failed

I am able to successfully build the tabs starter, so clearly this is an issue with my app. However, I’ve commented out most of my app.module.ts, leaving only:

//import {ContestPage} from '../pages/contest/contest';
//import {TradeView} from '../pages/trade/trade';
//import {GameView} from '../pages/game/game';
//import {SecurityService} from '../services/security.service';
//import {UserDataService} from '../services/userData.service';
import { NgModule } from '@angular/core';
import { IonicApp, IonicModule } from 'ionic-angular';
import { MyApp } from './app.component';
//import { HomeView } from '../pages/home/home';

@NgModule({
  /*declarations: [
    MyApp,
    HomeView,
    GameView,
    TradeView,
    ContestPage
  ],*/
  imports: [
    IonicModule.forRoot(MyApp)
  ],
  bootstrap: [IonicApp],
  entryComponents: [
//    MyApp,
//    HomeView
  ]/*,
  providers: [SecurityService, UserDataService]*/
})
export class AppModule {
}

The error is coming from the use of IonicModule.ForRoot it seems. As a result, I’m not sure where to go from here. Can anyone help?

2 Likes

I’m getting the same issue and am trying to work through fixing it. I’ll let you know what I find.

I got it actually. I deleted the entire node_modules folder and re-npm installed. Everything is good now.

Tried reinstalling all npm modules as well but with no result. Still getting:

ngc error: Error: 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 167:19 in the original .ts file), resolving symbol AppModule in .tmp/app/app.module.ts

You’re getting this error message because one or more of the NG2 plugins you’re using is missing the metadata file required for the AOT compilation. I had the same problem with the ng2-translate plugin, which they’ve fixed today by adding the metadata file.

Ok thanks! In which version have they fixed it? Currently I am using 3.0.0

I am having the same issue. Its suppose to be fix in the 3.0.0

Weird, I am using 3.0.0 but still the error…

Use this:

export function translateLoaderFactory(http: any) {
	return new TranslateStaticLoader(http, 'assets/i18n', '.json');
}

TranslateModule.forRoot({
    provide: TranslateLoader,
    useFactory: translateLoaderFactory,
    deps: [Http]
})

From: Router: AoT compilation fails

2 Likes

Thanks for the help. Where does this code go?
BTW, I have used Cordova before before. This is my first experience with Ionic or Ionic2. I can run on android but not ios.
I am getting this issue today with a brand new ‘ionic start ionictwoapple --v2’ (add a symbolic link) ‘ionic run ios’

I had to add a symbolic link to node_modules/tslint-eslint-rules to fix a different build error I encountered.

@JCollinsNN not sure about the seccond error. the first one add it to the app.module.ts, something like this:

import { NgModule } from ‘@angular/core’;
import { HttpModule, Http } from ‘@angular/http’;
import { TranslateModule } from ‘ng2-translate/ng2-translate’;
import { TranslateLoader, TranslateStaticLoader } from “ng2-translate/src/translate.service”;
import { IonicApp } from ‘ionic-angular’;
import { App } from ‘./app.component’;

export function translateLoaderFactory(http: any) {
return new TranslateStaticLoader(http, ‘assets/i18n’, ‘.json’);
}

@NgModule({
declarations: [
App,
],
imports: [
HttpModule,
TranslateModule.forRoot({
provide: TranslateLoader,
useFactory: translateLoaderFactory,
deps: [Http]
})
],
bootstrap: [IonicApp],
entryComponents: [
App,
],
providers: [
]
})
export class AppModule { }

1 Like

Thanks for the clarification. I had success with @bytenik 's suggestion to npm uninstall.
I did npm uninstall -g for ionic, cordova and angular/angular-cli packages, and then re-installed following:


That worked for me much cleaner than in my previous environment.

1 Like

What if I have to export a non-class, non-component object like

config.ts

export class CONFIG = { ... }

then reference it in app.module.ts

AoT compiler will throw the same error, how can I add metadata in this case?

2 Likes

Same error
Error: Error encountered resolving symbol values statically. Function calls are not supported. Consider
Packages.json
"dependencies": {
"@angular/common": “2.1.0”,
"@angular/compiler": “2.1.0”,
"@angular/compiler-cli": “0.6.2”,
"@angular/core": “2.1.0”,
"@angular/forms": “2.1.0”,
"@angular/http": “2.1.0”,
"@angular/platform-browser": “2.1.0”,
"@angular/platform-browser-dynamic": “2.1.0”,
"@angular/platform-server": “2.0.0”,
"@ionic/storage": “1.0.3”,
“ionic-angular”: “2.0.0-rc.1”,
“ionic-native”: “2.2.3”,
“ionicons”: “3.0.0”,
“rxjs”: “5.0.0-beta.12”,
“zone.js”: “0.6.21”,
“ng2-translate”: “3.1.3”
},
“devDependencies”: {
"@ionic/app-scripts": “latest”,
“typescript”: “2.0.3”,
“typings”: “1.4.0”
},

my app.moudle not contains useFactory

Have you found an answer to your question?
I’m struggling with essentially the same problem as part of https://github.com/driftyco/ionic-app-scripts/issues/762 and https://github.com/driftyco/ionic-app-scripts/pull/683.