0

I am currently working on reading a local file in react-native and am running into the following error,

TypeError:null is not an object(evaluating 'RNFSManager.RNFSFileTypeRegular')

The code I am using is taken straight off of the documentation for react-native-fs , using the basic example, from the examples section:

// require the module
var RNFS = require('react-native-fs');

// get a list of files and directories in the main bundle
RNFS.readDir(RNFS.MainBundlePath) // On Android, use "RNFS.DocumentDirectoryPath" (MainBundlePath is not defined)
  .then((result) => {
    console.log('GOT RESULT', result);

    // stat the first file
    return Promise.all([RNFS.stat(result[0].path), result[0].path]);
  })
  .then((statResult) => {
    if (statResult[0].isFile()) {
      // if we have a file, read it
      return RNFS.readFile(statResult[1], 'utf8');
    }

    return 'no file';
  })
  .then((contents) => {
    // log the file contents
    console.log(contents);
  })
  .catch((err) => {
    console.log(err.message, err.code);
  });

If it helps I am using vs when writing this on a Windows 10 computer.

I have tried resetting my cache, reinstalling react-native-fs, and linking react-native-fs, none have solved the problem all resulting in the same error.

I would greatly appreciate any help. Thank you.

Jescanellas
  • 2,289
  • 2
  • 7
  • 18
db1048
  • 51
  • 2

1 Answers1

1

In case of iOS message is 'Native module cannot be null', In Android message is 'null is not an object evaluating RNFSManager etc'

Solution for iOS is run pod install in iOS Directory, then react-native run-ios to re-run the app.

Solution for android is react-native link react-native-fs then react-native run-android to re-run the app.

Akhzar Nazir
  • 513
  • 5
  • 12