Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not work in NodeJS (ReactJS Native) #484

Open
wangjia184 opened this issue Mar 30, 2016 · 12 comments
Open

Does not work in NodeJS (ReactJS Native) #484

wangjia184 opened this issue Mar 30, 2016 · 12 comments

Comments

@wangjia184
Copy link

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?

@briancavalier
Copy link
Member

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!

@briancavalier
Copy link
Member

@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')?

@wangjia184
Copy link
Author

yes, only require cause an error

@wangjia184
Copy link
Author

facebook react native takes use of nodejs,but there must be some difference

@scothis
Copy link
Member

scothis commented Mar 30, 2016

Possibly related cujojs/rest#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.

@briancavalier
Copy link
Member

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?

@wangjia184
Copy link
Author

thank you ,please open one

@wangjia184
Copy link
Author

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

@briancavalier
Copy link
Member

Hey @wangjia184, thanks for the update. Do you mean that there is a bug in React Native?

@simison
Copy link

simison commented Nov 2, 2016

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": "[email protected]",
      "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+ (facebook/react-native@5710b23)

@aaerofeev
Copy link

aaerofeev commented Jun 1, 2017

I can not use this, the error always occurs because of the third-party say: "peer component invalid: [email protected]", when i using npm-shrinkwrap. Do you know other ways to fix this problem with whenjs
RN 0.44

@wangjia184
Copy link
Author

@beerTeam , try to use the minimal version of javascript file in nodejs. The minimal version should include when.js by itself.

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

No branches or pull requests

5 participants