Angular2-jwt: Error encountered resolving symbol values statically

Created on 28 Jul 2017  ·  10Comments  ·  Source: auth0/angular2-jwt

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 ?

stale

Most helpful comment

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

All 10 comments

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

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

@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 Try this. Worked for me.
export function tokenGetter(): string { return localStorage.getItem('access_token'); }
JwtModule.forRoot({ config: { tokenGetter, whitelistedDomains: ['localhost:3001'] } }),

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.

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

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

@alexnoise79, your comments solved my problem.

Thx!!!

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.

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

Related issues

UlyssesAlves picture UlyssesAlves  ·  5Comments

leosvelperez picture leosvelperez  ·  5Comments

guillaume-skwid picture guillaume-skwid  ·  5Comments

mahendra2125 picture mahendra2125  ·  4Comments

Eddman picture Eddman  ·  3Comments