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

Error encountered resolving symbol values statically

Open TheParad0X opened this issue 9 years ago • 10 comments

Not sure this is an angular2-jwt bug or an angular one: When running "ng serve" I get the following error:

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 (positi on 101:22 in the original .ts file), resolving symbol AppModule in C:/dev/.git/[...]app.module.ts

But when I simply save any file and the change detection triggers a reompilation, the error is gone. The line 101 is the following:

    JwtModule.forRoot({
      config: {
        tokenGetter: () => { // Line 101
          return localStorage.getItem('token');
        },
        whitelistedDomains: ['localhost:8080']
      }
    }),

So my console looks like this in the end:

** NG Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200 ** Hash: 0a221417cee5f4e344ea Time: 25991ms chunk {0} polyfills.bundle.js, polyfills.bundle.js.map (polyfills) 177 kB {5} [initial] [rendered] chunk {1} main.bundle.js, main.bundle.js.map (main) 95.3 kB {4} [initial] [rendered] chunk {2} styles.bundle.js, styles.bundle.js.map (styles) 441 kB {5} [initial] [rendered] chunk {3} scripts.bundle.js, scripts.bundle.js.map (scripts) 443 kB {5} [initial] [rendered] chunk {4} vendor.bundle.js, vendor.bundle.js.map (vendor) 6.29 MB [initial] [rendered] chunk {5} inline.bundle.js, inline.bundle.js.map (inline) 0 bytes [entry] [rendered]

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 (positi on 101:22 in the original .ts file), resolving symbol AppModule in C:/dev/.git/[...]app.module.ts webpack: Failed to compile. webpack: Compiling... Hash: 0a221417cee5f4e344ea Time: 4136ms chunk {0} polyfills.bundle.js, polyfills.bundle.js.map (polyfills) 177 kB {5} [initial] chunk {1} main.bundle.js, main.bundle.js.map (main) 95.3 kB {4} [initial] chunk {2} styles.bundle.js, styles.bundle.js.map (styles) 441 kB {5} [initial] chunk {3} scripts.bundle.js, scripts.bundle.js.map (scripts) 443 kB {5} [initial] chunk {4} vendor.bundle.js, vendor.bundle.js.map (vendor) 6.29 MB [initial] chunk {5} inline.bundle.js, inline.bundle.js.map (inline) 0 bytes [entry] webpack: Compiled successfully.

How come ?

TheParad0X avatar Jul 28 '17 14:07 TheParad0X

FYI: https://github.com/angular/angular-cli/issues/7146

TheParad0X avatar Aug 02 '17 11:08 TheParad0X

The tokenGetter seems to be creating a problem when used with Angular-Cli and AOT. Did you manage to find a solution?

codermannn avatar Aug 03 '17 00:08 codermannn

I don't think you pass a lamda function like that in forRoot pretty sure it has to be resolved statically.

jiverson avatar Aug 03 '17 07:08 jiverson

@jiverson how ?

So far I don't have a solution and I uninstalled angular2-jwt. The new Angular 4.3 HttpClient makes it really easy to implement the interceptor myself.

TheParad0X avatar Aug 03 '17 12:08 TheParad0X

@TheParad0X Try this. Worked for me. export function tokenGetter(): string { return localStorage.getItem('access_token'); } JwtModule.forRoot({ config: { tokenGetter, whitelistedDomains: ['localhost:3001'] } }),

codermannn avatar Aug 03 '17 23:08 codermannn

If you run ng serve and then implement the code there is no problem. I only encounter it if i stop the angular process and restart it. @lohiarahul solution worked for me, too.

vlkrrrr avatar Oct 06 '17 11:10 vlkrrrr

export function tokenGetter() {
  return localStorage.getItem('token');
}

@NgModule({
  imports: [
    JwtModule.forRoot({
      config: {
        tokenGetter: tokenGetter
      }
    })
  ]
})

alexnoise79 avatar Oct 13 '17 14:10 alexnoise79

@alexnoise79, your comments solved my problem.

Thx!!!

skormel avatar Dec 04 '17 08:12 skormel

I still got this issue that was discovered in 2016, What is going on with this library? I followed the original readme with the localstorage example and got the issue of AOT:

Function calls are not supported in decorators but 'parse' was called.

pinich avatar Dec 18 '18 17:12 pinich

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 03:10 stale[bot]