akveo / ngx-admin

Customizable admin dashboard template based on Angular 10+
https://akveo.github.io/ngx-admin/
MIT License
25.28k stars 7.96k forks source link

ERROR TypeError: Object(...) is not a function in role.provider using production mode #5790

Closed RoWEN-FCUB closed 3 years ago

RoWEN-FCUB commented 4 years ago

This is my role.provider copied from documentation:

import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { map } from 'rxjs/operators/map';

import { NbAuthService, NbAuthJWTToken } from '@nebular/auth';
import { NbRoleProvider } from '@nebular/security';

@Injectable()
export class RoleProvider implements NbRoleProvider {

  constructor(private authService: NbAuthService) {
  }

  getRole(): Observable<string> {
    return this.authService.onTokenChange()
      .pipe(
        map((token: NbAuthJWTToken) => {
          return token.isValid() ? token.getPayload()['role'] : 'guest';
        }),
      );
  }
}

When I use ng serve it works fine, but when change to ng build --prod I get this error:

ERROR TypeError: Object(...) is not a function
    getRole http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    value http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    set http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    Sa http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    ta http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    Bs http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    template http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    Ki http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    Qi http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    ma http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    Qi http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    Qi http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    ma http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    Qi http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    Qi http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    ma http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    Qi http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    Qi http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    Qi http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    Qi http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    ma http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    Qi http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    Qi http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    Wi http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    _a http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    _a http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    value http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    value http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    next http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    invoke http://localhost:4200/polyfills.77a57f56cea3670af0de.js:1
    onInvoke http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    invoke http://localhost:4200/polyfills.77a57f56cea3670af0de.js:1
    run http://localhost:4200/polyfills.77a57f56cea3670af0de.js:1
    value http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    next http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    o http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    value http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    value http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    value http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    value http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    value http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    value http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    Bf http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    onHasTask http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    hasTask http://localhost:4200/polyfills.77a57f56cea3670af0de.js:1
    _updateTaskCount http://localhost:4200/polyfills.77a57f56cea3670af0de.js:1
    _updateTaskCount http://localhost:4200/polyfills.77a57f56cea3670af0de.js:1
    runTask http://localhost:4200/polyfills.77a57f56cea3670af0de.js:1
    _ http://localhost:4200/polyfills.77a57f56cea3670af0de.js:1
    promise callback*v http://localhost:4200/polyfills.77a57f56cea3670af0de.js:1
    scheduleTask http://localhost:4200/polyfills.77a57f56cea3670af0de.js:1
    onScheduleTask http://localhost:4200/polyfills.77a57f56cea3670af0de.js:1
    scheduleTask http://localhost:4200/polyfills.77a57f56cea3670af0de.js:1
    scheduleTask http://localhost:4200/polyfills.77a57f56cea3670af0de.js:1
    scheduleMicroTask http://localhost:4200/polyfills.77a57f56cea3670af0de.js:1
    x http://localhost:4200/polyfills.77a57f56cea3670af0de.js:1
    E http://localhost:4200/polyfills.77a57f56cea3670af0de.js:1
    k http://localhost:4200/polyfills.77a57f56cea3670af0de.js:1
    r http://localhost:4200/runtime.4c98cd03fa6165e5b45a.js:1
    <anonymous> http://localhost:4200/5.6a7f6f4724152e8f0807.js:1
main.ad51f10eaa7c18ea889b.js:1:2787926
    gr http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    value http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    value http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    invoke http://localhost:4200/polyfills.77a57f56cea3670af0de.js:1
    run http://localhost:4200/polyfills.77a57f56cea3670af0de.js:1
    value http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    value http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    next http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    invoke http://localhost:4200/polyfills.77a57f56cea3670af0de.js:1
    onInvoke http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    invoke http://localhost:4200/polyfills.77a57f56cea3670af0de.js:1
    run http://localhost:4200/polyfills.77a57f56cea3670af0de.js:1
    value http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    next http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    o http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    value http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    value http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    value http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    value http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    value http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    value http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    Bf http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    onHasTask http://localhost:4200/main.ad51f10eaa7c18ea889b.js:1
    hasTask http://localhost:4200/polyfills.77a57f56cea3670af0de.js:1
    _updateTaskCount http://localhost:4200/polyfills.77a57f56cea3670af0de.js:1
    _updateTaskCount http://localhost:4200/polyfills.77a57f56cea3670af0de.js:1
    runTask http://localhost:4200/polyfills.77a57f56cea3670af0de.js:1
    _ http://localhost:4200/polyfills.77a57f56cea3670af0de.js:1
    (Asíncrono: promise callback)
    v http://localhost:4200/polyfills.77a57f56cea3670af0de.js:1
    scheduleTask http://localhost:4200/polyfills.77a57f56cea3670af0de.js:1
    onScheduleTask http://localhost:4200/polyfills.77a57f56cea3670af0de.js:1
    scheduleTask http://localhost:4200/polyfills.77a57f56cea3670af0de.js:1
    scheduleTask http://localhost:4200/polyfills.77a57f56cea3670af0de.js:1
    scheduleMicroTask http://localhost:4200/polyfills.77a57f56cea3670af0de.js:1
    x http://localhost:4200/polyfills.77a57f56cea3670af0de.js:1
    E http://localhost:4200/polyfills.77a57f56cea3670af0de.js:1
    k http://localhost:4200/polyfills.77a57f56cea3670af0de.js:1
    r http://localhost:4200/runtime.4c98cd03fa6165e5b45a.js:1
    <anonymous> http://localhost:4200/5.6a7f6f4724152e8f0807.js:1

Sin título2

this is my package.json :

"dependencies": {
    "@agm/core": "^1.1.0",
    "@akveo/ng2-completer": "^9.0.1",
    "@angular/animations": "^10.2.0",
    "@angular/cdk": "^10.2.5",
    "@angular/common": "^10.2.0",
    "@angular/compiler": "^10.2.0",
    "@angular/core": "^10.2.0",
    "@angular/forms": "^10.2.0",
    "@angular/localize": "^10.2.0",
    "@angular/platform-browser": "^10.2.0",
    "@angular/platform-browser-dynamic": "^10.2.0",
    "@angular/router": "^10.2.0",
    "@danielmoncada/angular-datetime-picker": "^10.0.0",
    "@fortawesome/angular-fontawesome": "^0.7.0",
    "@fortawesome/fontawesome-svg-core": "^1.2.32",
    "@fortawesome/free-solid-svg-icons": "^5.15.1",
    "@nebular/auth": "6.2.1",
    "@nebular/eva-icons": "6.2.1",
    "@nebular/security": "6.2.1",
    "@nebular/theme": "6.2.1",
    "@ng-bootstrap/ng-bootstrap": "^7.0.0",
    "@ngtools/webpack": "^10.2.0",
    "@swimlane/ngx-charts": "^16.0.0",
    "angular2-chartjs": "0.5.1",
    "bootstrap": "4.5.3",
    "chart.js": "^2.9.4",
    "ckeditor": "4.7.3",
    "classlist.js": "1.1.20150312",
    "core-js": "^3.6.5",
    "echarts": "^4.9.0",
    "eva-icons": "^1.1.3",
    "html-to-pdfmake": "^2.1.0",
    "intl": "1.2.5",
    "ionicons": "^2.0.1",
    "jquery": "^3.5.1",
    "leaflet": "1.7.1",
    "moment": "^2.29.1",
    "ncu": "^0.2.1",
    "nebular-icons": "1.1.0",
    "ng-number-picker": "^1.1.9",
    "ng2-ckeditor": "^1.2.9",
    "ng2-smart-table": "^1.7.0",
    "ngx-echarts": "^5.1.2",
    "ngx-export-as": "^1.5.0",
    "ngx-material-timepicker": "^5.5.3",
    "ngx-pagination": "^5.0.0",
    "node-sass": "^4.14.1",
    "normalize.css": "8.0.1",
    "pace-js": "1.0.2",
    "pdfmake": "^0.1.68",
    "popper.js": "^1.15.0",
    "roboto-fontface": "0.10.0",
    "rxjs": "^6.6.3",
    "rxjs-compat": "6.6.3",
    "socicon": "3.0.5",
    "style-loader": "^2.0.0",
    "sweetalert2": "^10.8.1",
    "tinymce": "5.5.1",
    "tslib": "^2.0.3",
    "typeface-exo": "1.1.13",
    "web-animations-js": "^2.3.2",
    "zone.js": "~0.11.2"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.1002.0",
    "@angular/cli": "^10.2.0",
    "@angular/compiler-cli": "^10.2.0",
    "@angular/language-service": "10.2.0",
    "@compodoc/compodoc": "^1.1.11",
    "@fortawesome/fontawesome-free": "^5.15.1",
    "@types/d3-color": "2.0.0",
    "@types/googlemaps": "^3.40.2",
    "@types/jasmine": "3.6.0",
    "@types/jasminewd2": "2.0.8",
    "@types/leaflet": "1.5.19",
    "@types/node": "^14.14.3",
    "codelyzer": "^6.0.1",
    "conventional-changelog-cli": "2.1.0",
    "husky": "4.3.0",
    "jasmine-core": "3.6.0",
    "jasmine-spec-reporter": "6.0.0",
    "karma": "5.2.3",
    "karma-chrome-launcher": "3.1.0",
    "karma-cli": "2.0.0",
    "karma-coverage-istanbul-reporter": "3.0.3",
    "karma-jasmine": "4.0.1",
    "karma-jasmine-html-reporter": "1.5.4",
    "npm-run-all": "4.1.5",
    "protractor": "7.0.0",
    "rimraf": "3.0.2",
    "stylelint": "13.7.2",
    "ts-node": "9.0.0",
    "tslint": "^5.20.1",
    "tslint-language-service": "^0.9.9",
    "typescript": "4.0.3"
  }
DarkStarGit commented 3 years ago

Hi, this code work for me

image

RoWEN-FCUB commented 3 years ago
let result;
    this.authService.onTokenChange().subscribe((token: NbAuthJWTToken) => {
      if (token.isValid()) {
        result = token.getPayload()['role'];
      } else {
        result = 'guest';
      }
    });
    return observableOf(result);

Thath gave me this error: Cannot find name 'observableOf'. Did you mean 'Observable'? And if I use return Observable.of(result); instead it shows ERROR TypeError: an.Observable is undefined and does not work.

RoWEN-FCUB commented 3 years ago

Solved.

getRole(): Observable<string> {
    let result;
    this.authService.onTokenChange().subscribe((token: NbAuthJWTToken) => {
      if (token.isValid()) {
        result = token.getPayload()['role'];
      } else {
        result = 'guest';
      }
    });    
    return of(result);
  }

Now it's working again.