RC0 - library dependency export (jwt-angular2, js-base64)

Mhh I have in my angular-jwt.js the folowing return value:

 angular.module('angular-jwt.jwt', [])
  .service('jwtHelper', ["$window", function($window) {

    this.urlBase64Decode = function(str) {
      var output = str.replace(/-/g, '+').replace(/_/g, '/');
      switch (output.length % 4) {
        case 0: { break; }
        case 2: { output += '=='; break; }
        case 3: { output += '='; break; }
        default: {
          throw 'Illegal base64url string!';
        }
      }
      return $window.decodeURIComponent(escape($window.atob(output))); //polyfill https://github.com/davidchambers/Base64.js
    };

Your angular2-jwt is old, you’ll need to update it

1 Like

How did you resolve depdencey on legacy angular lib?

└─┬ angular2-jwt@0.1.6
β”œβ”€β”€ angular2@2.0.0-beta.17
β”œβ”€β”€ UNMET PEER DEPENDENCY reflect-metadata@0.1.2
β”œβ”€β”€ UNMET PEER DEPENDENCY rxjs@5.0.0-beta.0
└─┬ zone.js@0.5.15
└── es6-promise@3.3.1

Oh the horror:

└── UNMET PEER DEPENDENCY rxjs@5.0.0-beta.6

npm WARN @angular/core@2.0.2 requires a peer of rxjs@5.0.0-beta.12 but none was installed.
npm WARN @angular/http@2.0.2 requires a peer of rxjs@5.0.0-beta.12 but none was installed.
npm WARN @ngrx/core@1.2.0 requires a peer of rxjs@^5.0.0-beta.12 but none was installed.
npm WARN @ngrx/store@2.2.1 requires a peer of rxjs@^5.0.0-beta.12 but none was installed.
npm WARN angular2@2.0.0-beta.17 requires a peer of reflect-metadata@0.1.2 but none was installed.
npm WARN ionic-angular@2.0.0-rc.1 requires a peer of rxjs@^5.0.0-beta.12 but none was installed.
npm ERR! code 1

That doesn’t seem to matter much and you can usually ignore it. But check your package json is similar to the one recommended for ionic 2 rc 1 (you should be on rxjs 5.0.0 beta 12 for instance) and make sure ionic us up to date as per the latest ionic changelog.

1 Like

Worked. I could compile the new jwt. Will report back. Thanks for your follow up.

How do you solve to check in altered code in node-modules and assure that your build system is taking your altered packages?

node_modules/angular2-jwt/angular2-jwt.ts:192:12

[15:13:49]  Cannot find name 'global'.

Darn it. Nothing is working. :frowning:

Good question! Altering the node module is a last resort. Another option would be to copy the module source into your project (as a libs folder or similar) and just build a fork of it.

Yea, altering node_module folder is definitive no option it seems. Do you know if angular-jwt will make their lib compatible to rollup ?

To be honest I stopped looking into it once it was fixed enough for me to move on.

I imagine if the proposed upcoming move to Webpack by default for Ionic happens this type of thing will be less of an issue (webpack is less aggressive about optimising based on declared exports).

Ok its working here now even without the global declaration. I am using x.x.26 angular-jwt and no problems there. Thanks for all your help and see you in the β€œjwt issues with webpack thread”. I guess since we used the full circle gulp, webpack, browserify and rollup we are then turing complete or something. :joy:

Look into using npm link in these situations.

1 Like