bluebird icon indicating copy to clipboard operation
bluebird copied to clipboard

Guard against falsey process.versions to support React Native

Open L8D opened this issue 5 years ago • 4 comments

I ran into this issue when working on a React Native project. When I imported bluebird, it would throw Cannot read property 'node' of undefined and I had to work around the problem by using Object.defineProperty(process, 'versions', ...) to get bluebird to work.

Strangely, this "bug" only became a problem after using bluebird in the project for a month or so. I haven't hunted down the culprit but it is populating global.process with an [object process]

I'm not sure if this is really the correct change, since this logic effects whether setImmediate/process.nextTick is used, and we probably want to use setImmediate in a React Native environment.

L8D avatar Jul 24 '18 17:07 L8D

I would suggest changing isNode, not isRecentNode.

Ginden avatar Aug 21 '18 08:08 Ginden

This is blocking debugging with VSCode. @L8D how was your workaround looking like?

And why changing isNode? I mean it is actually node running. But this introduces an compatibility issue with vscode.

mlostekk avatar Nov 14 '18 18:11 mlostekk

I am getting the same error while using bluebird with react native. RN: 0.57.5 Bluebird: 3.5.3

Is there anything I can do?

sreevisakh avatar Nov 22 '18 07:11 sreevisakh

I have fixed it temporarily like this

  1. Install node modules
  2. Open bluebird.js
  3. Modify the code for ret.isRecentNode to
ret.isRecentNode = ret.isNode && (function() {
    var version = process.version.split(".").map(Number);
    return (version[0] === 0 && version[1] > 10) || (version[0] > 0);
})();

mlostekk avatar Nov 22 '18 08:11 mlostekk