4

我正在尝试在我的应用程序中使用 react-native-fs 来上传文件等。我按照文档中的安装进行了导入,然后我将这段代码用于测试:

componentDidMount(){
    const path = RNFS.DocumentDirectoryPath + '/test.txt';
    console.log(path);
    // write the file
    RNFS.writeFile(path, 'Lorem ipsum dolor sit amet', 'utf8')
        .then((success) => {
            console.log('FILE WRITTEN!');
        })
        .catch((err) => {
            console.log(err.message);
    });
}

它直接给我这个错误:

在此处输入图像描述 ps:我通过 create-react-native-app 创建了我的项目

有任何想法吗?

4

1 回答 1

0

您需要在项目中链接 react-native fs 。在终端 react-native 链接 react-native-fs 中运行它

于 2018-01-25T22:34:28.567 回答