This breaks unhandledRejection handler for example.
$ node
> Promise
[Function: Promise]
> require('jszip')
{ [Function: JSZip]
support:
{ base64: true,
array: true,
string: true,
arraybuffer: true,
nodebuffer: true,
uint8array: true,
blob: false,
nodestream: true },
defaults:
{ base64: false,
binary: false,
dir: false,
createFolders: true,
date: null,
compression: null,
compressionOptions: null,
comment: null,
unixPermissions: null,
dosPermissions: null },
loadAsync: [Function],
external:
{ Promise:
{ [Function: lib$es6$promise$promise$$Promise]
all: [Function: lib$es6$promise$promise$all$$all],
race: [Function: lib$es6$promise$promise$race$$race],
resolve: [Function: lib$es6$promise$promise$resolve$$resolve],
reject: [Function: lib$es6$promise$promise$reject$$reject],
_setScheduler: [Function: lib$es6$promise$asap$$setScheduler],
_setAsap: [Function: lib$es6$promise$asap$$setAsap],
_asap: [Function: asap] } } }
> Promise
{ [Function: lib$es6$promise$promise$$Promise]
all: [Function: lib$es6$promise$promise$all$$all],
race: [Function: lib$es6$promise$promise$race$$race],
resolve: [Function: lib$es6$promise$promise$resolve$$resolve],
reject: [Function: lib$es6$promise$promise$reject$$reject],
_setScheduler: [Function: lib$es6$promise$asap$$setScheduler],
_setAsap: [Function: lib$es6$promise$asap$$setAsap],
_asap: [Function: asap] }
>
This wasn't intentional. This comes from the Promise implementation, see stefanpenner/es6-promise/issues/140 and stefanpenner/es6-promise/issues/141. Either we find a way to disable this or we change the implementation.
@dduponchel ah I see. And sorry for having been so terse :smiley:
This is how I currently fix this:
const p = Promise
require('jszip')
global.Promise = p
@dduponchel see https://github.com/kevinbeaty/any-promise. It allows user to select prefered promise library.
any-promise looks like a good option for nodejs, but I don't see an easy way to use it on an old brower (I get a any-promise browser requires a polyfill or explicit registration e.g: require('any-promise/register/bluebird')). Registering an implementation is not a good idea as a library and asking for a polyfill defeats the purpose of having an implementation in JSZip.external.Promise.
es6-promise should improve the situation in the future v4 but I don't know when it will be released (the code on their master branch still automatically call polyfill()). A fork + patch could work while waiting on this v4.
The other solution is to change the implementation. vow or lie look like good alternatives (working in IE 6, lightweight implementation).
Any ideas ?
@dduponchel It appears that lie is generally API-compatible with ES6 promises, so that might help.
@dduponchel as far as i remember, anypromise will use window.Promise in browser. IMHO it`s normal to say "you need Promise polyfill for old browsers" - it's the same as for es5 polyfills. Of cause, it's possible to create 2 web builds - pure one and with bulit-in promise lib.
Fixed in v3.1.0.
Most helpful comment
Fixed in v3.1.0.