admin管理员组

文章数量:1333691

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:

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 ponents for Bing Maps
 * @version v0.2.0
 * @link 
 * @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 ponents
   ],
  bootstrap:    [ ClientApp ],
  providers: [ 
    // our services
    ]
})

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./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 ponents for Bing Maps
 * @version v0.2.0
 * @link https://github./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 ponents
   ],
  bootstrap:    [ ClientApp ],
  providers: [ 
    // our services
    ]
})
Share Improve this question edited Oct 12, 2016 at 7:48 Mistalis 18.3k14 gold badges77 silver badges97 bronze badges asked Oct 12, 2016 at 1:16 BolandBoland 1,5711 gold badge15 silver badges44 bronze badges 1
  • show more of your base module. It's tough to get a good understanding of how you're using the BingMapsModule in context. – BeetleJuice Commented Oct 12, 2016 at 3:49
Add a ment  | 

3 Answers 3

Reset to default 3

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

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.

Had a similar problem while using redux reducers with Angular-cli. Solved it by exporting and wrapping the function in another function in the app module, and then using the exported function:

export function returnMainReducer(){
  return {mainReducer};
}

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    CoreModule,
    SharedModule,
    StoreModule.forRoot(returnMainReducer())
  ]

本文标签: javascriptAngular 202Error encountered resolving symbol values staticallyStack Overflow