4

In this case, I am requiring request-promise, but when I start the react native project, I get the error:

"Unable to resolve module x. If you are sure the module is there, try restarting the packager."

This error is reported for every dependency of the request dependency of request-promise. I have restarted the packager as well as removing node_modules and reinstalling. In general, what does this error stem from and in the specific, what can be done to solve it?

node v4.2.1, npm v2.14.7

4
  • Not sure, but to get some similar functionality as 'request-promise', have you tried using fetch? developer.mozilla.org/en-US/docs/Web/API/Fetch_API Commented Nov 3, 2015 at 17:07
  • fetch() and Promise() should work natively out of the box. I've had luck with that just as @NaderDabit has. In order to fix module import issues I've been able to clean the project out in Xcode, rebuild it, then run it again with no errors. Have you tried that? Commented Nov 3, 2015 at 17:11
  • These are requests made on the server...I was under the impression that fetch() was only available on the window object. Commented Nov 3, 2015 at 17:29
  • Surprisingly, for me, methods of the window object are available in react native, while none of the node core methods are. Thanks for the tip. Commented Nov 4, 2015 at 16:01

2 Answers 2

3

I've seen this error before trying to use another module. It drove me crazy for a bit. I created a reduction test isolating a new project to the one component. Once I saw it work, I knew it was something specific to the project. In my case, all I had to do was shut everything down and restart it all from scratch (can't recall if I went so far as to reboot my machine). Might have something to do with a cache? Not sure.

In summary...

  1. Create a reduction test to be sure you're using the module correctly
  2. Restart everything

In any case, here's the relevant bit of code in the core. Didn't give me any clues, but maybe you're smarter than me...

https://github.com/facebook/react-native/blob/b39b97546ac0e493723d73149c6950b04c2f203c/packager/react-packager/src/DependencyResolver/polyfills/require.js#L41

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks @ChrisGeirman - I have confirmed correct usage of the module outside of the inclusion in a react native iOS "scene", but for some reason when it is used within the context of the react native build, then these errors become an issue.
0

window methods, such as fetch, are available in react native, while node core methods are not.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.