kevinbeaty / any-promise

NOTE: You probably want native promises now
MIT License
179 stars 17 forks source link

Check that window exists first #29

Closed franciscop closed 5 years ago

franciscop commented 6 years ago

Hi, could you please check that window exists before checking its property?

https://github.com/kevinbeaty/any-promise/blob/master/register-shim.js#L10

// Fixed implementation:
function loadImplementation(){
  if(typeof window !== 'undefined' && typeof window.Promise === 'undefined'){
    throw new Error("any-promise browser requires a polyfill or explicit registration"+
      " e.g: require('any-promise/register/bluebird')")
  }
  return {
    Promise: window.Promise,
    implementation: 'window.Promise'
  }
}

Window will be undefined in Node.js contexts, so your script throws a TypeError. See more info:

https://github.com/harttle/liquidjs/issues/73