Invalid Directory /Users/node_modules/superagent with React Native


Invalid Directory /Users/node_modules/superagent with React Native

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?


Solution 1:

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

Solution 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.

Solution 3:

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 :