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

Invalid directory /Users/node_modules/Dimensions #3817

Closed
lprhodes opened this issue Nov 1, 2015 · 15 comments
Closed

Invalid directory /Users/node_modules/Dimensions #3817

lprhodes opened this issue Nov 1, 2015 · 15 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@lprhodes
Copy link
Contributor

lprhodes commented Nov 1, 2015

Hi,

I've just started using 0.14.0-rc and migrated from an early version. I opted to stop using CocoaPods and go it "alone" instead.

The directory structure is setup as per the result of "react-native init":

  • android
  • ios
  • index.ios.js
  • index.android.js
  • node_modules
  • package.son

Everything on the Obj-C side builds and runs in the iOS simulator

React native is giving the following error however:

Error while loading: Unable to resolve module Dimensions from any_npm_module: Invalid directory /Users/node_modules/Dimensions

Clearly that's an odd place to be looking for the module...

I'm digging into the code but has anyone any pointers?

Thanks

Luke

@lprhodes
Copy link
Contributor Author

lprhodes commented Nov 1, 2015

ResolutionRequest.js is redirecting the require()'s from the module... it looks through these search paths:

  • '/Users/username/Dropbox/Dev/project_name/node_modules/react-native-swiper/dist/node_modules/Dimensions'
  • '/Users/username/Dropbox/Dev/project_name/node_modules/react-native-swiper/node_modules/Dimensions'
  • '/Users/username/Dropbox/Dev/project_name/node_modules/node_modules/Dimensions'
  • '/Users/username/Dropbox/Dev/project_name/node_modules/Dimensions'
  • '/Users/username/Dropbox/Dev/node_modules/Dimensions'
  • '/Users/username/Dropbox/node_modules/Dimensions'
  • '/Users/username/node_modules/Dimensions'
  • '/Users/node_modules/Dimensions'

Then errors when the module could't be found. The problem of course is that Dimensions is in - '/Users/username/Dropbox/Dev/project_name/node_modules/react-native/Libraries/Utilities'

I assume that we should be checking the cache of react-native modules before checking the directories?

@lprhodes
Copy link
Contributor Author

lprhodes commented Nov 1, 2015

...I can change the library to use import { Dimensions } from 'react-native' but as it used to work and I couldn't find any mention of this being a breaking change require('Dimensions') should be allowed to work.

@lprhodes
Copy link
Contributor Author

lprhodes commented Nov 1, 2015

If I add custom potential paths to the searchQueue in ResolutionRequest.js I end up with a working app. This obviously won't be the best way to get to the top level of the react-native module and we would want to include paths recursively but as a quick demo it works:

searchQueue.push( path.resolve(__dirname + '/../../../../../Libraries/Utilities/' + toModuleName));
searchQueue.push( path.resolve(__dirname + '/../../../../../Libraries/StyleSheet/' + toModuleName));

@ide
Copy link
Contributor

ide commented Nov 1, 2015

The @providesModule pragmas within the react-native package are meant to be a private detail. Requiring modules directly has undefined behavior i.e. best not to rely on it. Use the standard Node/npm style of going through the public API and requiring react-native.

@lprhodes
Copy link
Contributor Author

lprhodes commented Nov 1, 2015

I do for my own code but unfortunately I can't say the same for various modules I use. It could be a useful compatibility mechanism.

I also couldn't figure out how to import StyleSheetRegistry. This wasn't working:

import { StyleSheetRegistry} from 'react-native'

Admittedly I'm not all that used to the import style so maybe I'm missing something.

@nicholasalanbrown
Copy link

I'm getting the same error upon update but with static images:

Unable to resolve module <imagename> from path/to/component/code Invalid directory /Users/node_modules/<imagename>

Agreed, I'm not sure why React Native is looking there - everything looks fine on the Xcode side and it worked before update.

@nicholasalanbrown
Copy link

Ah, this was my fault - assets need to be included different in React Native 0.14.0+

holmesal added a commit to holmesal/react-native-carousel that referenced this issue Nov 10, 2015
In react-native 0.14.2, directly `require()`ing `Dimension` throws a packager error. It should be imported via the destructuring syntax instead. 

See:
facebook/react-native#3817
@jaygarcia
Copy link
Contributor

I've run into this as well and backed out of 14.x because of it. I'm seeing other custom modules receiving the same type of error.

almost/react-native-sqlite#33 (comment)

@nicholasalanbrown, what did you do to resolve this?

@nicholasalanbrown
Copy link

@jaygarcia well my specific issue was with include local image assets - the solution is above. I'm also seeing it with other packages that try and require NativeModules directly - I don't think there's a fix other than editing the package require statement itself. As far as I can tell, this is a breaking change that wasn't called out in the release docs. I'm not sure why it wasn't implemented as a warning rather than a complete failure point. It does really suck that those packages will be useless until their authors make the change. You could submit a PR to the author to expedite the process.

@jaygarcia
Copy link
Contributor

@vjeux @nicklockwood @frantic can you guys weigh in on this? This seems to affect everyone who's extending React Native.

@jkolyer
Copy link

jkolyer commented Nov 12, 2015

@nicholasalanbrown Can you be more specific about the fix you made for the assets error. Not clear to me exactly what you did.

@frantic
Copy link
Contributor

frantic commented Nov 19, 2015

@jaygarcia are any of the folders under node_modules symlinks? Packager has a hacky script that tries to guess the repo root, and it may cause problems with symlinks (cc @martinbigio)

@alubling
Copy link

alubling commented Dec 9, 2015

Just ran into the same error with Dimensions. Looks like there are other issues with packager but i thought i'd mention this. Changing to destructuring syntax off of the react native object instead of require or import of the Dimensions package directly fixed the issue for me.

Per: nick/react-native-carousel#24

@satya164
Copy link
Contributor

Closing in favor of #4968 . Let's track it there.

@ddalev
Copy link

ddalev commented Aug 8, 2016

Node js have group of possible folders that can contain modules. When you install one module sometimes module can be dependent to other modules. You have to install this dependancies manual. For example if the error is like /Users/node_modules/module you have to install "npm install -S module". 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

@facebook facebook locked as resolved and limited conversation to collaborators Jul 20, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

10 participants