I'm getting this error Invalid Directory /Users/node_modules/superagent
with a React Native project. I'm not sure why it would be looking for the module in this location? How can I fix this to search for the module inside the node_modules
directory of the React Native project where it is actually located?

- 455
- 6
- 23
-
I'm getting the same thing but for Firebase with React Native. – Tyler McGinnis Nov 22 '15 at 23:46
-
Getting the same thing for the `events` module – Louis Nov 23 '15 at 04:52
-
My fix was restarting the Node server, hadn't done so since the `npm install` command – Louis Nov 23 '15 at 04:58
-
I'm having the same issue. Are you using a .babel_rc file? I have the feeling it's related to that. – JWindey Nov 23 '15 at 10:54
-
How are you requiring `superagent` (assuming you're explicitly including it at all)? – Mark Amery Nov 23 '15 at 15:18
-
@MarkAmery I'm just doing `var superagent = require('superagent'); ` the same way I include all my modules. – Spencer Pope Nov 23 '15 at 15:53
-
@JWindey I don't think I am using a .babel_rc file. Should I be? – Spencer Pope Nov 23 '15 at 18:17
3 Answers
The problem is npm3. You have to downgrade it to npm2 because the flattened packages don't seem to work yet with react-native.

- 195
- 4
-
1I was about to say "[this guy seems to have the same issue, and have reached the same conclusion about how to fix it](https://github.com/facebook/react-native/issues/4296)" but then I noticed that he was you. – Mark Amery Nov 23 '15 at 14:58
-
Is there a specific version of npm I should use. I tried just doing `npm install -g npm@latest-2` but that didn't seem to fix anything. – Spencer Pope Nov 23 '15 at 15:57
-
Maybe try npm@2 instead of latest-2? Also don't forget to remove your node_modules folder before doing npm i again. I also discovered this error when you run a project that contains another package.json in one of the subfolders. Verify that too. – JWindey Nov 24 '15 at 05:53
I may be running into a similar issue over at Using PubNub with React Native
I used nvm to downgrade to Node v4.2.2 and then npm dropped itself automatically to 2.14.7. Re-created the React Native project (using react-native init
) so that there was no longer a flat modules directory. However, still getting the same error when requiring.
Node js have group of possible folders that can contain modules. When you install one module sometimes module can be dependent to other modules. I spend all day to understand that. You have to install this dependancies manual. In your case npm install -S superagent
. It is showing error as missing path in /Users/node_modules because this is the last element of array full with possible paths that can contain modules (for MAC).
Full list of paths by OS : https://www.npmjs.com/package/npm-paths

- 1
- 1