【问题标题】:TypeError:null is not an object(evaluating 'RNFSManager.RNFSFileTypeRegular')TypeError:null 不是对象(评估 'RNFSManager.RNFSFileTypeRegular')
【发布时间】:2019-12-20 15:24:40
【问题描述】:

我目前正在阅读 react-native 中的本地文件,并遇到以下错误,

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

我使用的代码是直接从 documentation for react-native-fs 中提取的,使用示例部分的基本示例:

// 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);
  });

如果它有助于我在 Windows 10 计算机上编写此代码时使用 vs。

我尝试过重置缓存、重新安装 react-native-fs 和链接 react-native-fs,但都没有解决问题,都导致相同的错误。

我将非常感谢任何帮助。谢谢你。

【问题讨论】:

  • 您是否为应用提供了写入权限?
  • 我没有特别授权。但我使用 react-native 开发其他应用程序,从未遇到任何问题。

标签: react-native react-native-fs


【解决方案1】:

如果 iOS 消息是“本机模块不能为空”,Android 消息是“null 不是评估 RNFSManager 等的对象”

iOS 的解决方案是在 iOS 目录中运行 pod install,然后 react-native run-ios 重新运行应用程序。

android 的解决方案是react-native link react-native-fs 然后react-native run-android 重新运行应用程序。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-01-13
    • 2020-11-21
    • 2021-05-27
    • 2021-12-29
    • 2020-03-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多