I get getting the following error after running my Angular 5 (Angular CLI 1.5) project with angular2-jwt 1.0.0-beta9:
ERROR in Error: No NgModule metadata found for 'AppModule'.
This is due to the Angular compiler not being able to retrieve the module information from the forRoot method call. I'm not sure what has to be done from here, but it's messing up CLI compilation. Attached my ng -v output:
Angular CLI: 1.5.0
Node: 9.0.0
OS: darwin x64
Angular: 5.0.1
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
@angular/cdk: 5.0.0-rc0
@angular/cli: 1.5.0
@angular/material: 5.0.0-rc0
@angular-devkit/build-optimizer: 0.0.33
@angular-devkit/core: 0.0.20
@angular-devkit/schematics: 0.0.35
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.8.0
@schematics/angular: 0.1.3
typescript: 2.4.2
webpack: 3.8.1
If I can help somehow, please feel free to contact me.
I read in another module that is a problem because the module doesn't have a metadata
+1
@doncabron I fixed:
export function gettoken (){
return localStorage.getItem('access_token');
};
const jwtConf: JwtModuleOptions = {
config: {
tokenGetter: gettoken,
whitelistedDomains: ['thanks.com','noproblem.com']
}
}
then
imports: [
JwtModule.forRoot(jwtConf),
Thanks. fertandil87's fix also fixed a compile error I was getting in Angular 5.2.1:
Function expressions are not supported in decorators
Consider changing the function expression into an exported function
It doesn't like the documentation's recommended uses of
tokenGetter: () => syntax
I also stumbled upon the error Function expressions are not supported in decorators Consider changing the function expression into an exported function and can confirm that fertandil87's fix works for me.
I would like to remind that the README's usage section gives the AOT-incompatible fat-arrow function definition for the tokenGetter, creating headaches for those who don't know about the error or this thread solution.
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! 🙇♂️
Most helpful comment
@doncabron I fixed:
export function gettoken (){
return localStorage.getItem('access_token');
};
const jwtConf: JwtModuleOptions = {
config: {
tokenGetter: gettoken,
whitelistedDomains: ['thanks.com','noproblem.com']
}
}
then
imports: [
JwtModule.forRoot(jwtConf),