React native TypeError:null不是对象(正在计算';RNFSManager.RNFSFileTypeRegular';)
我目前正在用react native读取本地文件,遇到以下错误React native TypeError:null不是对象(正在计算';RNFSManager.RNFSFileTypeRegular';),react-native,react-native-fs,React Native,React Native Fs,我目前正在用react native读取本地文件,遇到以下错误 TypeError:null不是对象(评估“RNFSManager.RNFSFileTypeRegular”) 我使用的代码直接取自示例部分的基本示例: // require the module var RNFS = require('react-native-fs'); // get a list of files and directories in the main bundle RNFS.readDir(RNFS.Mai
TypeError:null不是对象(评估“RNFSManager.RNFSFileTypeRegular”)
我使用的代码直接取自示例部分的基本示例:
// 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);
});
如果有帮助的话,我在Windows10计算机上写这篇文章时使用的是vs
我尝试过重置缓存、重新安装react-native fs和链接react-native fs,但没有一个解决了问题,所有这些都导致了相同的错误
我将非常感谢任何帮助。多谢各位 如果iOS消息为“本机模块不能为null”,则Android消息为“null不是评估RNFSManager等的对象” iOS的解决方案是在iOS目录中运行
pod install
,然后react native run iOS
重新运行应用程序
android的解决方案是
react native link react native fs
然后react native run android
重新运行该应用程序。您是否提供了该应用程序的写入权限?我没有明确授予它权限。但我曾使用react native开发其他应用程序,从未遇到过任何问题。