React-native-fs: Invariant Violation: Native module cannot be null.

Created on 15 Aug 2020  路  7Comments  路  Source: itinance/react-native-fs

Added react-native-fs to my project and receive an Invariant Violation error. Project is using Expo not sure if this is the issue.
My code:
Screenshot_20200814_173211

Error:
IMG-0689

I have confirmed that my react-native-fs version is compatible with by react-native version.

Any recommendations?

Most helpful comment

@ghasemikasra39 I found a solution:
create a __mocks__/react-native-fs.js file in your main directory with the following:

const mockedModule = jest.mock('react-native-fs');
module.exports = mockedModule;

then run npm test and should be fine!

All 7 comments

Seems like your pods didn't install properly try:

cd ios && pod install && cd ..

And try again.

I have the same issue!
I run cd ios && pod install && cd .. but the issue remain

Came across the same issue.

I have missed to update Podfile with following.

pod 'RNFS', :path => '../node_modules/react-native-fs'

Worked fine after doing a pod install. Refer - https://github.com/itinance/react-native-fs#usage-ios

I have the same issue and really hesitate to eject expo to update the Podfile

Updated: We change to use expo file system instead
https://docs.expo.io/versions/latest/sdk/filesystem/

I get this error in testing environment only with Jest. Any solution ?

@ghasemikasra39 I have the same issue!

@ghasemikasra39 I found a solution:
create a __mocks__/react-native-fs.js file in your main directory with the following:

const mockedModule = jest.mock('react-native-fs');
module.exports = mockedModule;

then run npm test and should be fine!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zaheerahmad92001 picture zaheerahmad92001  路  3Comments

quietautumn picture quietautumn  路  4Comments

wangfpp picture wangfpp  路  3Comments

PimDeWitte picture PimDeWitte  路  4Comments

opoze picture opoze  路  3Comments