IdentityModel / oidc-token-manager

Apache License 2.0
51 stars 36 forks source link

Promise error when using RequireJS #29

Closed promontis closed 9 years ago

promontis commented 9 years ago

Hi guys,

We've been seeing an error when using the oidc-token-manager within IE11 while using RequireJS (http://requirejs.org/).

Unable to get property 'Promise' of undefined or null reference

The error is because of the following piece of code:

    /* global define:true module:true window: true */
    if (typeof define === 'function' && define['amd']) {
      define(function() { return es6$promise$umd$$ES6Promise; });
    } else if (typeof module !== 'undefined' && module['exports']) {
      module['exports'] = es6$promise$umd$$ES6Promise;
    } else if (typeof this !== 'undefined') {
      this['ES6Promise'] = es6$promise$umd$$ES6Promise;
    }

    window.Promise = window.Promise || this['ES6Promise'].Promise; // do this to access Promise directly

RequireJS uses define to load its modules. It also has a valid 'amd' object. This will match the first condition and will let the library use ES6 promises. However, IE11 doesn't seem to support this.

The solution should be to improve the first condition to allow the use of RequireJS. I think you'll need to use a different condition for checking if the library should use ES6 promises.

promontis commented 9 years ago

We also get this error when running unit tests in PhantomJS. Same issue: RequireJS will let the library use ES6 promises, but PhantomJS doesn't seem to support it

brockallen commented 9 years ago

Yea, I know there are some issues with the promise implementation being used. I'm swamped, so I'll get top it as soon as I get some time. Sorry.

brockallen commented 9 years ago

Also, is this the same issue? https://github.com/IdentityModel/oidc-client/issues/13

If so, then we can close this as a dup.

promontis commented 9 years ago

Jup! Dup :) closing