react-native-fs
react-native-fs copied to clipboard
Unable to get property RNFSFileTypeRegular of undefined or null reference.
I followed the latest react-native-windows get started(https://microsoft.github.io/react-native-windows/docs/getting-started) and npm install react-native-fs
. Just a pure boilerplate react-native 0.65 app.
However npx react-native run-windows
which supposed to autolink react-native-fs seemed not working so I did manual linking:
"dependencies": {
"react": "17.0.2",
"react-native": "0.65.1",
"react-native-fs": "^2.18.0",
"react-native-windows": "0.65.2"
},
Super simple set up, but I'm getting this Unable to get property RNFSFileTypeRegular of undefined or null reference.
Error when I try to use RNFS like this:
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow strict-local
*/
import React from 'react';
import type {Node} from 'react';
var RNFS = require('react-native-fs');
...
const App: () => Node = () => {
console.log(RNFS?.DocumentDirectoryPath);
...
};
Anyone has similar problem? Any ideas??
I am running into this exact same error message. It works fine running on an Android or iOS device but not in the Windows target (run-windows
). In fact, I found that it worked fine on Android and iOS without needing to run npx react-native link react-native-fs
-- it just worked with what I assume is auto-linking. Running that command only modifies two Android build files and the iOS pod file -- nothing in the Windows build files.
Did you ever get this resolved? If so, I'd love to hear your solution. If not, what instructions did you follow for manual linking? The manual link in the RNFS readme, https://github.com/Microsoft/react-native-windows/blob/main/docs/LinkingLibrariesWindows.md, does not appear to work anymore (404 page). I'd like to try to troubleshooting this tomorrow, and getting to the same point you are would be a big step. Thanks!
I've solved this in my project.
Background: here's the react-native-fs PR that's supposed to fix this issue (I did not write it!) https://github.com/itinance/react-native-fs/pull/952 I don't know why it hasn't been merged yet -- it appears to have been ready for over a month now.
Here is a specific comment showing that if you switch your package.json to the PR, you'll get the fixed code and your project will work again in the Windows environment. https://github.com/microsoft/react-native-windows/issues/2829#issuecomment-709615605
So, here are all the commands you need:
yarn remove react-native-fs
yarn add https://github.com/avmoroz/react-native-fs.git#dev
npx react-native run-windows
Afterward, not only will it run, it will modify the project.sln, AutolinkedNativeModules.g.cpp and AutolinkedNativeModules.g.targets. I did not need to run any manual link commands, but my project now runs with run-windows
, run-android
, and run-ios --device "<device-name>"
.
HOWEVER, note that due to the nature of my app, I have not actually tested the RNFS portion in Windows because it's in a module that only works on a mobile device (camera image capture and upload). But this is still a big deal because the rest of the app can be worked on directly in the UWP environment, without a physical mobile device or even a simulator. Given that the PR is ready to be merged, I expect that it will function correctly in the UWP environment.
Not working for me, any solution?
I've solved this in my project.
Background: here's the react-native-fs PR that's supposed to fix this issue (I did not write it!) #952 I don't know why it hasn't been merged yet -- it appears to have been ready for over a month now.
Here is a specific comment showing that if you switch your package.json to the PR, you'll get the fixed code and your project will work again in the Windows environment. microsoft/react-native-windows#2829 (comment)
So, here are all the commands you need:
yarn remove react-native-fs yarn add https://github.com/avmoroz/react-native-fs.git#dev npx react-native run-windows
Afterward, not only will it run, it will modify the project.sln, AutolinkedNativeModules.g.cpp and AutolinkedNativeModules.g.targets. I did not need to run any manual link commands, but my project now runs with
run-windows
,run-android
, andrun-ios --device "<device-name>"
.HOWEVER, note that due to the nature of my app, I have not actually tested the RNFS portion in Windows because it's in a module that only works on a mobile device (camera image capture and upload). But this is still a big deal because the rest of the app can be worked on directly in the UWP environment, without a physical mobile device or even a simulator. Given that the PR is ready to be merged, I expect that it will function correctly in the UWP environment.
When I used yarn add https://github.com/avmoroz/react-native-fs.git#dev, it showed me that OpenSSL SSL_read: Connection was reset, errno 10054.
So what's up with this bug?
Using the react-native-fs
from https://github.com/avmoroz/react-native-fs.git#dev
indeed fixed the linking issue, but the build failed because it requires older Win SDK. And of course it's not really a long term solution until merged.
Any updates? npx react-native run-windows this is not working for me
When I try the dev branch I get an error with the wrong windows SDK version:
Build failed with message 3:10>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.Cpp.WindowsSDK.targets(46,5): error MSB8036: The Windows SDK version 10.0.18362.0 was not found. Install the required version of Windows SDK or change the SDK version in the project property pages or by right-clicking the solution and selecting "Retarget solution". [C:\dev\testReactNative\node_modules\react-native-fs\windows\RNFS\RNFS.vcxproj]. Check your build configuration.
Command failed. Re-run the command with --logging for more information.
I got it working by following the error instructions, I opened the solution under node_modules in visual studio and retargeted it for my installed version of the windows sdk. Not ideal! - trying to figure out how to fix it better
I fixed the version issue in avmoroz's branch and pushed my own upgraded version. This now works in one step for me:
npm uninstall react-native-fs
npm install https://github.com/a-leut/react-native-fs#dev
npx react-native run-windows
I tried to use this package, but when I execute yarn add https://github.com/a-leut/react-native-fs#dev, there is an error described "fatal: unable to access 'https://github.com/a-leut/react-native-fs/': OpenSSL SSL_read: Connection was reset, errno 10054" or "Failed to connect to github.com port 443 after 21112 ms: Time out". I‘m sure that I can use yarn to download other packages. And I also can download react-native-fs-dev by "Download Zip" from github.. How can I use yarn to download it? Or how should I use downloaded react-native-fs-dev in my project to use RNFS?
@gangli66 if you're using yarn version 2+ I think you need the prepend the package name like in the second answer here: https://stackoverflow.com/questions/43411864/how-to-install-package-from-github-repo-in-yarn
yarn add '<package name>@https://github.com/<github user>/<github repo>'
I invested so much in React Native to discover that simple file access is F'edup. Should have sticked to the .Net eco.