Registry / data / react-native-fs

react-native-fs

JSON →
library2.20.0jsnpmunverified

react-native-fs provides comprehensive native filesystem access for React Native applications across iOS, Android, and Windows platforms. It offers a robust API for common file operations such as reading, writing, and deleting files, managing directories, and facilitating advanced use cases like background file downloads and uploads with progress tracking. The library is actively maintained, with the current stable version being 2.20.0, and receives regular updates to address compatibility with new React Native versions and underlying OS changes, exemplified by recent fixes for iOS crashes and Android type corrections. A key differentiator is its direct native integration, enabling features like handling content URIs on Android and asset video URIs on iOS, which are crucial for complex media and document management within mobile applications. It carefully manages compatibility across various React Native versions, requiring specific `react-native-fs` versions depending on the host `react-native` and Gradle versions, highlighting its sensitivity to the broader ecosystem.

npm install react-native-fs
INSTALL
IMPORT
SIG · REACT-NATIVE-FS
R
react-native-fs
datajavascriptv2.20.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

RNFS
import RNFS from 'react-native-fs';
import { RNFS } from 'react-native-fs';
The library primarily uses a default export pattern where `RNFS` is the main object containing all methods and constants.
DocumentDirectoryPath
import RNFS from 'react-native-fs'; const path = RNFS.DocumentDirectoryPath;
import { DocumentDirectoryPath } from 'react-native-fs';
Constants like directory paths are properties of the default `RNFS` export.
RNFS (CommonJS)
const RNFS = require('react-native-fs');
For older React Native projects or environments that still rely on CommonJS modules. Modern projects should prefer ESM imports.

This example demonstrates basic file operations: writing a string to a temporary file, reading its content, checking its existence, retrieving its statistics, and finally deleting it. It uses `RNFS.TemporaryDirectoryPath` for cross-platform compatibility.

import RNFS from 'react-native-fs'; const fileName = 'test.txt'; const content = 'Hello from react-native-fs!'; const filePath = `${RNFS.TemporaryDirectoryPath}/${fileName}`; async function runFsExample() { try { // 1. Write a file await RNFS.writeFile(filePath, content, 'utf8'); console.log(`File written to: ${filePath}`); // 2. Read the file const readContent = await RNFS.readFile(filePath, 'utf8'); console.log(`File content: ${readContent}`); if (readContent !== content) { throw new Error('Content mismatch!'); } // 3. Check if file exists const exists = await RNFS.exists(filePath); console.log(`File exists: ${exists}`); // 4. Get file stats const statResult = await RNFS.stat(filePath); console.log(`File size: ${statResult.size} bytes`); // 5. Delete the file await RNFS.unlink(filePath); console.log(`File deleted: ${filePath}`); const deletedExists = await RNFS.exists(filePath); console.log(`File exists after deletion: ${deletedExists}`); } catch (error) { console.error('An error occurred during FS operations:', error); } } runFsExample();
Debug
Known issues
breakingBreaking changes in compatibility with React Native versions require specific `react-native-fs` versions. Failure to install the correct version will lead to build errors or runtime crashes.
fix
For RN < 0.57, install `@2.11.17`. For RN >= 0.57 and Gradle >= 3, install `>= @2.13.2`. For RN >= 0.61, install `>= @2.16.0`.
affects: <=2.20.0
breaking`react-native-fs` versions prior to `2.14.0` do not support AndroidX. Projects migrating to AndroidX must upgrade.
fix
Upgrade to `react-native-fs` version `2.14.0` or higher to gain AndroidX support. Ensure your Android project is fully migrated to AndroidX.
affects: <2.14.0
breakingThe `size` property returned by file `stat` operations changed from `Int` to `Double` for increased precision, particularly affecting larger files.
fix
Update any code that relies on the `size` property to expect a `Double` instead of an `Int`.
affects: <2.14.0
gotchaOn Android, the `DocumentDirectory` is strictly mapped to the application's private `files` directory. This differs from iOS, where it might have broader permissions or map to different system directories. Access to external storage requires additional permissions and may not be directly supported through this path.
fix
Be aware of Android's scoped storage and file access limitations. For external storage, consider using methods like `ExternalStorageDirectoryPath` or `DownloadDirectoryPath` and ensure appropriate permissions (`READ_EXTERNAL_STORAGE`, `WRITE_EXTERNAL_STORAGE`) are declared and requested at runtime.
affects: >=2.1.0
gotchaiOS background downloads require specific setup and careful handling of sessions. Improper configuration can lead to downloads failing or not resuming correctly.
fix
Follow the 'Background Downloads Tutorial (iOS)' in the official documentation carefully. Ensure `Manually flush & invalidate session upon completion` (as fixed in v2.17.0) is considered when managing download tasks.
affects: >=2.0.0
gotchaOlder versions of `react-native-fs` (< 2.19.0) did not properly implement `addListener` and `removeListeners` methods, leading to `NativeEventEmitter` warnings in newer React Native environments.
fix
Upgrade to `react-native-fs` version `2.19.0` or higher to resolve `NativeEventEmitter` warnings.
affects: <2.19.0
Errors
Common errors & fixes
Invariant Violation: `new NativeEventEmitter()` was called with a non-null argument without the native module implementing `addListener` and `removeListeners`.
Using `react-native-fs` with a React Native version that expects `NativeEventEmitter` compliance, but the installed `react-native-fs` version is too old.
fix
Upgrade `react-native-fs` to version `2.19.0` or newer: `npm install react-native-fs@latest` or `yarn add react-native-fs@latest`.
Undefined symbol: _OBJC_CLASS_$_RCTImageLoader
iOS build failure due to changes in React Native's internal `RCTImageLoader` import paths (specifically for RN > 0.60).
fix
Upgrade `react-native-fs` to version `2.15.1` or higher, which includes a fix for this issue by importing `RCTImageLoaderProtocol`.
TypeError: Cannot read property 'DocumentDirectoryPath' of undefined
The `RNFS` native module was not correctly linked or initialized, or the JavaScript import is incorrect.
fix
Ensure the library is properly linked (using `react-native link react-native-fs` or manual linking as per documentation). Verify the import statement is `import RNFS from 'react-native-fs';`.
Task 'assembleRelease' failed. Android resource linking failed.
Common Android build issue, often related to AndroidX migration status or incorrect Gradle configuration.
fix
Verify that your `react-native-fs` version supports your AndroidX migration status (v2.14.0+ for AndroidX). Check your `android/app/build.gradle` and `android/settings.gradle` for correct `react-native-fs` package inclusion, especially if using manual linking.
Upgrade
Version history
2.20.0latest on npm
Audit
Dependencies
react-nativerequiredRequired for all React Native applications using this library.
react-native-windowsoptionalPeer dependency for React Native Windows support.
Agent activity
62 hits · last 30 days
node
54
OpenAI (training)
1
Resources
react-native-fs — npm install react-native-fs · libregistry