【发布时间】: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