I get the error message: "Cannot read property 'readDir' of undefined"
When I add this line:
var RNFS = require('react-native-fs');
I am testing on the IOS simulator.
Are you sure that linking RNFS.xcodeproj right?
Same error here. I've linked everything using rnpm link react-native-fs. To solve the problem, try to install the module using the github repo:
npm install react-native-fs@https://github.com/johanneslumpe/react-native-fs --save
rnpm link react-native-fs
Is this still an issue with the new 1.5 release?
@johanneslumpe I'm blocked by this issue in 1.5.1.
@mkraft are you linking the project correctly? It seems a bit weird to me, because else we'd have quite a few more issues about this.
@mkraft @johanneslumpe I agree, this smells of the native module not being loaded into memory. Can you triple check that you have linked the .a file with the binary in Build Phases?
You need to run react-native run-android/run-ios after installing before you can just reload the javascript. Reason being the module has native components that will not be installed yet if you do not do a full build first
I get a similar problem in android using 1.5.1, but only on an app that's deployed to the app store. It crashes immediately. Works fine in dev mode, and works fine in iOS so far.
07-29 09:07:27.915 23705-23746/? E/AndroidRuntime: FATAL EXCEPTION: mqt_native_modules
com.facebook.react.modules.core.JavascriptException: undefined is not an object (evaluating 'i.readDir'), stack:
<unknown>@629:187
o@2:517
e@2:326
i@2:188
<unknown>@628:299
o@2:517
e@2:326
i@2:188
<unknown>@365:1403
o@2:517
e@2:326
i@2:188
<unknown>@12:101
o@2:517
e@2:256
i@2:188
global code@635:9
at com.facebook.react.modules.core.ExceptionsManagerModule.showOrThrowError(ExceptionsManagerModule.java:94)
at com.facebook.react.modules.core.ExceptionsManagerModule.reportFatalException(ExceptionsManagerModule.java:78)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.facebook.react.bridge.BaseJavaModule$JavaMethod.invoke(BaseJavaModule.java:319)
at com.facebook.react.bridge.NativeModuleRegistry$ModuleDefinition.call(NativeModuleRegistry.java:187)
at com.facebook.react.bridge.NativeModuleRegistry.call(NativeModuleRegistry.java:62)
at com.facebook.react.bridge.CatalystInstanceImpl$NativeModulesReactCallback.call(CatalystInstanceImpl.java:432)
at com.facebook.react.bridge.queue.NativeRunnableDeprecated.run(Native Method)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31)
at android.os.Looper.loop(Looper.java:137)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:193)
at java.lang.Thread.run(Thread.java:856)
07-29 09:07:27.945 1654-1673/? E/android.os.Debug: !@Dumpstate > dumpstate -k -t -z -d -o /data/log/dumpstate_app_error
Same issue here. I tried the github repo then I get this:
Unhandled JS Exception: undefined is not an object (evaluating 'RNFSManager.NSFileTypeRegular')
I think it's from here: https://github.com/johanneslumpe/react-native-fs/blob/master/FS.common.js#L17
I have rnpm installed but it also throws an error, but i did verify that both the library and the link are configured in xcode
I am having a similar issue with another module, so I think this might be an issue outside of this module - possibly undocumented or broken in react native
Ok, I found part of the issue was that the files weren't included right. If you are using Deco to build the app, after you do all the xcode includes for the libraries, you also have to tell Deco to 'Build Native Modules'

Using version 1.5.1 with react-antive 0.29.2. Did the rnmp link. iOS works smoothly, have the same problem on Android.
This is the error:
File externalStorageDirectory = this.getReactApplicationContext().getExternalStorageDirectory(null);
^
symbol: method getExternalStorageDirectory(
location: class ReactApplicationContext
Note:
I have this issue as well. I've installed and manually added with XCode. But when I added the line "var RNFS = require('react-native-fs');" and run 'react-native run-ios', I get this error:
Unhandled JS Exception: undefined is not an object (evaluating 'RNFSManager.NSFileTypeRegular')
However, when I run the project directly from XCode, I don't have this error. Not sure why that is, or how I can fix the issue so that I can have it working when I run 'react-native run-ios'. Thoughts?
Same here.
Works when I run from XCode, but does not work from command line react-native run-ios.
npm start --reset-cachereact-native link react-native-fsrm -rf node_modules && npm installRN 0.32
RNFS 2.0.1-rc.2 (got it straight from npm)
I have a couple of other native packages which runs fine:
Just to ensure I have done the right thing.
What does the asterisk indicate in the linking instructions?
Add the lib*.a from the RNFS project
I added a file called libRNFS.a. Is this the file referred to as lib*.a?
Same problem with RNFS 1.5.1.
Steps:
react-native unlink react-native-fsnpm install https://github.com/johanneslumpe/react-native-fs.git#1.5.1 --saveRuns fine from XCode but not from command line.
I really need to handle some files in my caches folder. Are there no other alternatives than RNFS for React Native?
Unfortunately, I don't have the knowledge to dig deeper into the code. Please instruct me if anyone needs more test data. The problem is totally reproducible at my computer.
SOLVED.
I upgraded from RN0.32 to 0.33. Either the new RN version made it work or the fresh xcode-proj I got after react-native upgrade. I'm guessing the latter.
Here is what I did:
npm install [email protected]react-native upgradereact-native link react-native-fs If you don't want to upgrade RN I'd guess that your linking problems will be solved by just following steps 2-4.
I'm getting the same error on android with a fresh install of RN 0.34.1.
undefined is not an object (evaluation 'RNFSManager.RNFSFileTypeRegular')
Problem seems to be in line 17 in FS.common.js
var RNFSFileTypeRegular = RNFSManager.RNFSFileTypeRegular;
Where RNFSManager is for some reason not imported
Does anyone know what has changed in RN 0.34.1 to cause NativeModules not to include RNFSManager ? Or if there is possibly another explanation? I have already verified that the module is linked.
I followed @michaelswe's instructions and got it working so it seems this component is not working with latest react native version (0.34.1). Any ideas how to get it working? If someone can point me in the right direction I might be able to submit a pull request
Unfortunately I cannot set aside any of my time to work on this library :/
@johanneslumpe no problem, I was hoping maybe someone of the other contributors knew something about the issue
I realized this was a linking error. Somehow it got linked correctly when I used RN 0.33 but not RN 0.34. After installing again in a RN 0.34 project and manually linking I got it working just like with 0.33
I had the same issue, in my case
01-08 04:56:28.183 1742-1788/com.ghinwa E/ReactNativeJS: undefined is not an object (evaluating 'RNFSManager.readDir')
This problem is solved following the "Usage (Android)" guide in the README.md for your exact version of react-native.
馃憤
Most helpful comment
You need to run react-native run-android/run-ios after installing before you can just reload the javascript. Reason being the module has native components that will not be installed yet if you do not do a full build first