Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2.0.2 - Error encountered resolving symbol values statically

I'm also running into the famous 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 ", when running i18n. I've already done a lot of research, and I'm not using a lambda function. It happens when I add the following import statement to my base module:

export const mapsConfig = new LazyMapsAPILoaderConfig();
mapsConfig.apiKey = 'xyz';
// ... below is in import list
BingMapsModule.forRoot(config),

I'm using ng2-bingmaps, which I've contributed to as well: https://github.com/youjustgo/ng2-bingmaps

The weird thing is that it does not matter what the JS code is in ng2-bingmaps. If I remove all .js files, I still get the same error! So, it must be something in the ng2-bingmaps core.d.ts which looks like this:

/**
 * ng2-bingmaps - Angular 2 components for Bing Maps
 * @version v0.2.0
 * @link https://github.com/youjustgo/ng2-bingmaps
 * @license MIT
 */
import { ModuleWithProviders } from '@angular/core';
import { LazyMapsAPILoaderConfig } from './services/maps-api-loader/lazy-maps-api-loader';
export * from './directives';
export * from './services';
export declare const NG2_BINGMAPS_PROVIDERS: any[];
/**
 * The ng2-bing-maps core module. Contains all Directives/Services/Pipes
 * of the core module. Please use `BingMapsModule.forRoot(config)` in your app module.
 *
 * @experimental
 */
export declare class BingMapsModule {
    static forRoot(config: LazyMapsAPILoaderConfig): ModuleWithProviders;
}

When I just import BingMapsModule (without the forRoot), it works.

I have checked all providers in ng2-bingmaps, and none of them have lambda functions inside the decorators.

My base module definition:

@NgModule({
  imports: [ 
    // browser module, required to load in browser
    BrowserModule, 
    // routing
    RouterModule.forRoot(routes),
    // angular forms
    FormsModule,
    // ng2-bingmaps
    BingMapsModule.forRoot(mapsConfig),
    // ng-bootstrap
    NgbModule,
    // http
    HttpModule,

    // Angulartics2
    // Angulartics2Module.forRoot(),
    // our custom modules for certain parts of our app
    CreateBookingModule,
    CommonModule
  ],
  declarations: [ 
    // all our components
   ],
  bootstrap:    [ ClientApp ],
  providers: [ 
    // our services
    ]
})
like image 972
Boland Avatar asked Oct 12 '16 01:10

Boland


2 Answers

"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 "

Though I've never seen this error, it sounds like it's referring to this

export const mapsConfig = new LazyMapsAPILoaderConfig();

If the mapsConfig is in the same file as the module you're using it in, there shouldn't be a need to export it. I imagine removing the export should solve the error.

Another thing, you probably don't need to create an instance of the config. You could just use an object literal because of TypeScript's structural type system

BingMapsModule.forRoot({
  apiKey: 'xyz'
})

Generally with "config" objects, this is how you will see it used anyway.

like image 133
Paul Samsotha Avatar answered Nov 14 '22 22:11

Paul Samsotha


In the end I've resolved it, thanks the @peeskillet for the answer.

  1. Using an object literal instead of a configuration object.
  2. ng2-bingmaps did not contain the required *.metadata.json files; each .d.ts file apparently requires this.
like image 29
Boland Avatar answered Nov 14 '22 22:11

Boland