Skip to content
This repository has been archived by the owner on Dec 6, 2023. It is now read-only.

reduce is not a function: avn should force mz to use bluebird as its Promise implementation #38

Closed
mwolson opened this issue Feb 1, 2016 · 5 comments

Comments

@mwolson
Copy link

mwolson commented Feb 1, 2016

One of my colleagues is seeing this when trying to install avn today on nodejs 4.2.6:

/Users/john/.avn/node_modules/bluebird/js/main/promise.js:677
            throw e;
            ^

TypeError: fs.readFile(...).catch(...).then(...).reduce is not a function
    at Object.exports._all (/Users/john/.avn/lib/plugins.js:56:4)
    at Object.all (/Users/john/.avn/lib/plugins.js:21:38)
    at Object.exports.first (/Users/john/.avn/lib/plugins.js:84:33)
    at match (/Users/john/.avn/lib/hooks.js:29:18)
    at Object.<anonymous> (/Users/john/.avn/lib/hooks.js:76:29)
    at Object.tryCatcher (/Users/john/.avn/node_modules/bluebird/js/main/util.js:26:23)
    at Promise._settlePromiseFromHandler (/Users/john/.avn/node_modules/bluebird/js/main/promise.js:507:31)
    at Promise._settlePromiseAt (/Users/john/.avn/node_modules/bluebird/js/main/promise.js:581:18)
    at Promise._settlePromises (/Users/john/.avn/node_modules/bluebird/js/main/promise.js:697:14)
    at Async._drainQueue (/Users/john/.avn/node_modules/bluebird/js/main/async.js:123:16)
    at Async._drainQueues (/Users/john/.avn/node_modules/bluebird/js/main/async.js:133:10)
    at Immediate.Async.drainQueues [as _onImmediate] (/Users/john/.avn/node_modules/bluebird/js/main/async.js:15:14)
    at processImmediate [as _immediateCallback] (timers.js:383:17)

When tracing through this, it seems like the promise returned from fs.readFile (via the mz module) is actually a native ES6 Promise instead of a bluebird Promise. But since avn relies on the reduce() method, which is not part of the ES6 Promise spec, it should probably force mz to use bluebird as its Promise implementation. Per https://www.npmjs.com/package/mz , the way to do this seems to be:

require('any-promise/register')('bluebird');

This may also need an update to mz 2.3.1

@wbyoung
Copy link
Owner

wbyoung commented Feb 2, 2016

The best course of action will probably be to do as you've suggested, but for now have opened normalize/mz#31.

@ljharb
Copy link

ljharb commented Feb 2, 2016

another alternative is to just use standard promise methods, instead of bluebird-specific ones.

@wbyoung
Copy link
Owner

wbyoung commented Feb 2, 2016

@ljharb yeah… the convenience methods are quite nice, though. 😄 And since this isn't a lib consumed by others, I think we'll just register it.

@wbyoung wbyoung closed this as completed in de7850c Feb 3, 2016
@wbyoung
Copy link
Owner

wbyoung commented Feb 3, 2016

Fix released npm in 0.2.3. Please let me know if you have any problems with it.

@mwolson
Copy link
Author

mwolson commented Feb 3, 2016

We've confirmed the fix; thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants