Angular2-jwt: Error encountered resolving symbol values statically. Function calls are not supported. Consider replacing the function or lambda with a reference to an exported function

Created on 8 Mar 2017  ·  7Comments  ·  Source: auth0/angular2-jwt

Hi,

I'm trying to call a service provider from aap.module.ts but im receiving an error below:

"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 45:19 in the original .ts file), resolvin
g symbol AppModule in C:/Users/neos/WebstormProjects/WWPortal/src/app/app.module.ts"

Here's the app.module.ts code:

`import { Http, Response, ResponseOptions, RequestMethod } from '@angular/http';
import { MockBackend, MockConnection } from '@angular/http/testing';
import { BaseRequestOptions } from '@angular/http';

providers: [
AuthGuard,
AuthenticationService,
UserService,
{
provide: Http,
useFactory: function (backend: MockBackend, options: BaseRequestOptions) {
// configure fake backend
backend.connections.subscribe((connection: MockConnection) => {
let testUser = { username: 'test', password: 'test', firstName: 'Test', lastName: 'User' };

      // wrap in timeout to simulate server api call
      setTimeout(() => {

        // fake authenticate api end point
        if (connection.request.url.endsWith('/api/authenticate') && connection.request.method === RequestMethod.Post) {
          // get parameters from post request
          let params = JSON.parse(connection.request.getBody());

          // check user credentials and return fake jwt token if valid
          if (params.username === testUser.username && params.password === testUser.password) {
            connection.mockRespond(new Response(
              new ResponseOptions({ status: 200, body: { token: 'fake-jwt-token' } })
            ));
          } else {
            connection.mockRespond(new Response(
              new ResponseOptions({ status: 200 })
            ));
          }
        }

        // fake users api end point
        if (connection.request.url.endsWith('/api/users') && connection.request.method === RequestMethod.Get) {
          // check for fake auth token in header and return test users if valid, this security is implemented server side
          // in a real application
          if (connection.request.headers.get('Authorization') === 'Bearer fake-jwt-token') {
            connection.mockRespond(new Response(
              new ResponseOptions({ status: 200, body: [testUser] })
            ));
          } else {
            // return 401 not authorised if token is null or invalid
            connection.mockRespond(new Response(
              new ResponseOptions({ status: 401 })
            ));
          }
        }

      }, 500);

    });

    return new Http(backend, options);
  },
  deps: [MockBackend, BaseRequestOptions]
},
// providers used to create fake backend
// fakeBackendProvider,
MockBackend,
BaseRequestOptions,
MockConnection

],

Please assist thank you.`

stale

Most helpful comment

I was fighting with this issue for a week. What i found was, that angular2-jwt documentation has:

import { NgModule } from '@angular/core';
import { Http, RequestOptions } from '@angular/http';
import { AuthHttp, AuthConfig } from 'angular2-jwt';

function authHttpServiceFactory(http: Http, options: RequestOptions) {
  return new AuthHttp(new AuthConfig(), http, options);
}

@NgModule({
  providers: [
    {
      provide: AuthHttp,
      useFactory: authHttpServiceFactory,
      deps: [Http, RequestOptions]
    }
  ]
})
export class AuthModule {}

where this is the problematic fuction:
function authHttpServiceFactory(http: Http, options: RequestOptions) { return new AuthHttp(new AuthConfig(), http, options); }
and just change it to
**export** function authHttpServiceFactory(http: Http, options: RequestOptions) { return new AuthHttp(new AuthConfig(), http, options); }

All 7 comments

Found the solution:

Try:

`export function httpFactory(backend: XHRBackend, defaultOptions: RequestOptions, globalService: GlobalService) {
return new HttpLoading(backend, defaultOptions, globalService);
}

providers: [
GlobalService,
{
provide: Http,
useFactory: httpFactory,
deps: [XHRBackend, RequestOptions, GlobalService]
}
],`

I was fighting with this issue for a week. What i found was, that angular2-jwt documentation has:

import { NgModule } from '@angular/core';
import { Http, RequestOptions } from '@angular/http';
import { AuthHttp, AuthConfig } from 'angular2-jwt';

function authHttpServiceFactory(http: Http, options: RequestOptions) {
  return new AuthHttp(new AuthConfig(), http, options);
}

@NgModule({
  providers: [
    {
      provide: AuthHttp,
      useFactory: authHttpServiceFactory,
      deps: [Http, RequestOptions]
    }
  ]
})
export class AuthModule {}

where this is the problematic fuction:
function authHttpServiceFactory(http: Http, options: RequestOptions) { return new AuthHttp(new AuthConfig(), http, options); }
and just change it to
**export** function authHttpServiceFactory(http: Http, options: RequestOptions) { return new AuthHttp(new AuthConfig(), http, options); }

The popular solution here didn't work for me. ng serve will fail initially, and then when I make a small change, the cli will recompile and succeed!

I have zero clue how to fix this - but it will prevent production builds from succeeding so it is a high priority.

My experience is described perfectly be wcxaaa's comment on a different ticket for the same issue: https://github.com/angular/angular-cli/issues/3707

i got the same error when typing ng serve or ng build at the first time.

is there a solution thats works well ?.

Is very important for me continue with the project, if the error continues i will have to migrate to another JWT solution for an angular app.

Hi Edward,

I had the same issue got it resolved by replacing fake-backend.ts code with the code available at the following file present on github.
https://github.com/cealmees/Angular2-training/blob/master/src/app/entities/login/helpers/fake-backend.ts

Some information is also available at the following link
http://stackoverflow.com/questions/41781781/angular-2-error-encountered-resolving-symbol-values-statically-from-mockbackend

Thanks

Hello All,
i am also facing the same issue, the error which i am getting is : ERROR in Error encountered resolving symbol values statically. Calling function 'BreadcrumbModule', function calls are not supported. Consider replacing the function or lambda with a reference to an exported function, please help me to resolve this issue.

Thanks

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you have not received a response for our team (apologies for the delay) and this is still a blocker, please reply with additional information or just a ping. Thank you for your contribution! 🙇‍♂️

Was this page helpful?
0 / 5 - 0 ratings