angular2-jwt icon indicating copy to clipboard operation
angular2-jwt copied to clipboard

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

Open neosoko opened this issue 9 years ago • 7 comments

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

neosoko avatar Mar 08 '17 07:03 neosoko

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] } ],`

neosoko avatar Mar 08 '17 14:03 neosoko

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); }

MFProduction avatar Mar 09 '17 14:03 MFProduction

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

efreethy-revprep avatar Apr 12 '17 18:04 efreethy-revprep

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.

EdwardMCastrillon avatar Apr 21 '17 15:04 EdwardMCastrillon

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

zohaib-buyer avatar Apr 23 '17 17:04 zohaib-buyer

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

Akhilesh601 avatar Oct 30 '17 03:10 Akhilesh601

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! 🙇‍♂️

stale[bot] avatar Oct 26 '19 05:10 stale[bot]