Open wangjia184 opened 8 years ago
Hi @wangjia184. I don't use FB React Native, but when certainly works in Node.js versions 0.8 thru 5.x. Can you provide a bit more context about the example code you showed?
when.lift(all)
For example, what is all
? The purpose of when.lift
is to take a non-promise-returning function, and give you back a promise-returning version of that function. So, the input to when.lift
(in this case, all
), must be a function.
Also, can you provide a complete stack trace of the error?
Thanks!
@wangjia184 Sorry, I realize I misunderstood the issue. So, just want to make sure I understand: the error you are seeing is coming from within when.js itself, and not from code you've written, simply by calling require('when')
?
yes, only require cause an error
facebook react native takes use of nodejs,but there must be some difference
Possibly related https://github.com/cujojs/rest/issues/137
In this case, it looks like the browser bundle is trying to be loaded, but can't be resolved correctly. I'm not sure why the browser bundle is trying to be loaded, or why it can't be found.
Yeah, it does look like it could be related, @scothis.
Since when.js is known to work on a wide variety of platforms, it probably also makes sense to open an issue with react native, as it looks like they have been working out kinks in their module loading. Apparently, they do override or modify node's require
, and it doesn't quite line up with node's conventions in some cases.
Plus, they may be able to help us more quickly than we could figure this out on our own!
@wangjia184 Do you want to do that, or want me to do it?
thank you ,please open one
My colleague managed to fix the problem, it seems the file path is incorrect in React Native..
For example require('../lib...)
should be require('../../lib....')
Hope he can send a pull request
Hey @wangjia184, thanks for the update. Do you mean that there is a bug in React Native?
I solved this issue by creating a npm-shrinkwrap.json
file and overwriting browser
field which was causing issues:
{
"dependencies": {
"when": {
"version": "3.7.7",
"from": "when@3.7.7",
"browser": false
}
}
}
Overwrites this: https://github.com/cujojs/when/blob/master/package.json#L75-L78
@briancavalier it's really easy and quick to set up React Native test app if you wanna do some further testing around this problem; it should be pretty easy to solve.
If I would hit this issue by using when
directly, I'd just switch to using something else instead. Now I hit the problem trough sub-dependencies (of Mopidy) so I had to fix it with this hack.
This works only with React Native v0.35+ (https://github.com/facebook/react-native/commit/5710b230a2a0f2b29553fbf94af5147a2e030f44)
I can not use this, the error always occurs because of the third-party say: "peer component invalid: react@16.0.0-alpha.6", when i using npm-shrinkwrap. Do you know other ways to fix this problem with whenjs RN 0.44
@beerteam , try to use the minimal version of javascript file in nodejs. The minimal version should include when.js by itself.
When loading this component in nodejs via
require
, Facebook React Native environment. It ends with error "undefined is not a function (evaluating 'when.lift(all)')"Any idea how can I fix this issue?