8

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?

Spencer Pope
  • 455
  • 6
  • 23

3 Answers3

4

The problem is npm3. You have to downgrade it to npm2 because the flattened packages don't seem to work yet with react-native.

JWindey
  • 195
  • 4
  • 1
    I 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
2

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.

Community
  • 1
  • 1
Fenda
  • 1,385
  • 3
  • 14
  • 24
-1

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