[🐛⚠️] iOS Build Fails - Value of optional type '?' must be unwrapped to refer to member 'storage' of wrapped base type 'any StorageProvider' (Optional Chaining)
Scenario
Last week I was able to compile my project (Expo EAS Build) without errors.
Today, without modifying anything (didn't upgrade any dependency), I have started getting this error on my iOS AdHoc compilation:
Run Fastlane Errors
Copying @react-native-firebase/storage ../../../Users/expo/Library/Developer/Xcode/DerivedData/Advice-dzlzwedukqkcvxgkbpzvxdpjkyli/Build/Intermediates.noindex/ArchiveIntermediates/Advice/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/FirebaseStorage.framework/Headers/FirebaseStorage-umbrella.h ➜ ios/Pods/Target/ Support/ Files/FirebaseStorage/FirebaseStorage-umbrella.h
› Copying @react-native-firebase/storage ../../../Users/expo/Library/Developer/Xcode/DerivedData/Advice-dzlzwedukqkcvxgkbpzvxdpjkyli/Build/Intermediates.noindex/ArchiveIntermediates/Advice/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/FirebaseStorage.framework/Headers/FIRStorageTypedefs.h ➜ ios/Pods/FirebaseStorage/FirebaseStorage/Typedefs/FIRStorageTypedefs.h
❌ (/Users/expo/workingdir/build/packages/app/ios/Pods/FirebaseStorage/FirebaseStorage/Sources/Storage.swift:73:12)
71 | let provider = ComponentType<StorageProvider>.instance(for: StorageProvider.self,
72 | in: app.container)
> 73 | return provider.storage(for: Storage.bucket(for: app))
| ^ value of optional type '?' must be unwrapped to refer to member 'storage' of wrapped base type 'any StorageProvider'
74 | }
75 |
76 | /**
❌ (/Users/expo/workingdir/build/packages/app/ios/Pods/FirebaseStorage/FirebaseStorage/Sources/Storage.swift:88:12)
86 | let provider = ComponentType<StorageProvider>.instance(for: StorageProvider.self,
87 | in: app.container)
> 88 | return provider.storage(for: Storage.bucket(for: app, urlString: url))
| ^ value of optional type '?' must be unwrapped to refer to member 'storage' of wrapped base type 'any StorageProvider'
89 | }
90 |
91 | /**
❌ (/Users/expo/workingdir/build/packages/app/ios/Pods/FirebaseStorage/FirebaseStorage/Sources/Storage.swift:291:39)
289 | init(app: FirebaseApp, bucket: String) {
290 | self.app = app
> 291 | auth = ComponentType<AuthInterop>.instance(for: AuthInterop.self,
| ^ cannot assign value of type '?' to type 'any AuthInterop'
292 | in: app.container)
293 | appCheck = ComponentType<AppCheckInterop>.instance(for: AppCheckInterop.self,
294 | in: app.container)
❌ (/Users/expo/workingdir/build/packages/app/ios/Pods/FirebaseStorage/FirebaseStorage/Sources/Storage.swift:293:47)
291 | auth = ComponentType<AuthInterop>.instance(for: AuthInterop.self,
292 | in: app.container)
> 293 | appCheck = ComponentType<AppCheckInterop>.instance(for: AppCheckInterop.self,
| ^ cannot assign value of type '?' to type 'any AppCheckInterop'
294 | in: app.container)
295 | storageBucket = bucket
296 | host = "firebasestorage.googleapis.com"
Package Versions
Since I was using the following dependencies
"@react-native-firebase/analytics": "^18.7.3",
"@react-native-firebase/app": "^18.7.3",
"@react-native-firebase/auth": "^18.7.3",
"@react-native-firebase/firestore": "^18.7.3",
"@react-native-firebase/functions": "^18.7.3",
"@react-native-firebase/storage": "^18.7.3",
I decided to upgrade to the latest one @^19.0.0.
"@react-native-firebase/analytics": "^19.0.0",
"@react-native-firebase/app": "^19.0.0",
"@react-native-firebase/auth": "^19.0.0",
"@react-native-firebase/firestore": "^19.0.0",
"@react-native-firebase/functions": "^19.0.0",
"@react-native-firebase/storage": "^19.0.0",
I have also tried upgrading EAS with Expo 48, 49 and the latest release and images, with CocoaPods v1.15.2, and the error still persists.
Is anyone experiencing the same issue?
Yes. I just got exactly the same error today, while everything worked fine last week. I am using Expo 49 SDK. The following is a part of my package.json.
"dependencies": { "@react-native-firebase/app": "^18.4.0", "@react-native-firebase/auth": "^18.4.0", "@react-native-firebase/firestore": "^18.4.0", "@react-native-firebase/storage": "^18.4.0", "expo": "~49.0.10", "react": "18.2.0", "react-native": "^0.72.6", }, "devDependencies": { "@babel/core": "^7.20.0" }, "private": true }
Given the error, "value of optional type '?' must be unwrapped to refer to member 'storage' of wrapped base type 'any StorageProvider", which indicates that the Swift compiler expects an optional value to be unwrapped before its properties or methods can be accessed, I think that it is more about the Firebase Storage SDK's internal handling of values than our project's code directly. I hope someone can help. Thanks
Yep, it’s a minimal issue with nils handling. Hope it’s fixed soon 🥺 I downgraded the package too but nothing. Did you try @17.5.0? @geoffcfchen
Starting to think the issue itself is in the latest Google Firebase iOS SDK package and not directly in this wrapper for React Native (?).
Yep, i assume its an already fixed issue in Firebase iOS sdk https://github.com/firebase/firebase-ios-sdk/pull/12391
guard let provider = ComponentType<StorageProvider>.instance(for: StorageProvider.self,
in: app.container) else {
fatalError("No \(StorageProvider.self) instance found for Firebase app: \(app.name)")
}
return provider.storage(for: Storage.bucket(for: app, urlString: url))
@mikehardy @Salakar
@VictorioMolina could you share how you solve this issue? Just reinstall react-native-firebase/storage? I am using expo EAS build right now and would appreciate it if you could share some advice. Thanks!
17.5.0
No I did not try 17.5.0...
Thanks for sharing the information. It seems to me that this problem is still not resolved. It was fine last week but now it can't work, so I think that there are some changes under the hood. I hope some one can point us in a direction...
Btw, how do you know it is related to https://github.com/firebase/firebase-ios-sdk/pull/12391?
@geoffcfchen take a look at the changes introduced on FirebaseStorage/Sources/Storage.swift in this commit:
https://github.com/firebase/firebase-ios-sdk/commit/1ed6d66b2010539bf21abf66b942dcf89384bd75
That’s why I feel we need to update the firebase iOS sdk to a greater version than v10.21.0
I see.
Since I am working on the expo project, I only have the following packages in my package.json
"@react-native-firebase/app": "18.9.0",
"@react-native-firebase/auth": "18.9.0",
"@react-native-firebase/firestore": "18.9.0",
"@react-native-firebase/storage": "18.9.0",
and the following plugins in app.json.
"plugins": [
"expo-apple-authentication",
"@react-native-firebase/app",
"@react-native-firebase/auth",
[
"expo-build-properties",
{
"ios": {
"useFrameworks": "static"
}
}
],
But I think that we encountered the same issue. I don't think that we are the only one. Those who used the EAS build recently should also encounter the same issue...
@geoffcfchen It’s correct, it seems impossible to build with expo in the current state. Ignore the custom config plug-in I was implementing, it’s not working and looks like a hack which could lead to extra problems… definitively, not a good solution, I am deleting it.
We will need to wait for the package maintainers.
Someone mentioned a solution
https://stackoverflow.com/questions/78027770/upgrading-to-expo-50-can%C2%B4t-build-ios
But it requires ejecting from Expo...
@geoffcfchen It's not the same issue but I also faced it today.
"plugins": [
"@react-native-firebase/app",
"./src/plugins/maps/withReactNativeMaps",
"./src/plugins/splash/withAndroidSplashScreen",
[
"expo-build-properties",
{
"android": {
"compileSdkVersion": 34,
"targetSdkVersion": 34,
"buildToolsVersion": "34.0.0",
"extraProguardRules": "-keep class com.google.android.gms.internal.consent_sdk.** { *; }"
},
"ios": {
"deploymentTarget": "13.4", <-------- Just upgrade the minimum deployment target for iOS
"useFrameworks": "static"
}
}
],
[
"expo-notifications",
{
"icon": "./assets/images/logo/notification/notification-icon.png",
"color": "#ffffff"
}
]
],
There is no need to eject to the bare workflow, you can stay managed or semi-managed with EAS.
Maybe a related post
https://github.com/firebase/flutterfire/issues/12429
I don't using expo, i use cli and the error occurs there too
@geoffcfchen yep, it’s the same issue. Also, it seems the solution is just to upgrade the firebase iOS sdk version, but, as I mentioned before, I feel it’s not the best approach to touch the Podfile with an expo plugin. It’s better to wait for the maintainers of react-native-firebase.
any updates?
any updates?
@AleshkovDenis @vladi-klmv I submitted a pull request to fix the issue. Pls, check it out and if you think something is missing, update it :) or create a patch package. This issue is strongly retaining us.
@VictorioMolina Did you try build your app with patched package changes?
@AleshkovDenis Nop, I didn't, just prefer to wait for any updates on this repo. But if you do, let us know if the sdk version upgrade fixes the issue.
@VictorioMolina and @AleshkovDenis - the sdk version upgrade does fix the issue when you patch the package.
If anyone would like to use this solution while we wait on the official update, it's very straightforward with a tool like patch-package, or if you use yarn v2+ or pnpm, those have built-in support for package patching.
Here's how I did it on Yarn v2+ (I use 4.0.2):
- Run
yarn patch @react-native-firebase/app - Navigate to the folder location output by the yarn patch command
- Update package.json L76 to
"firebase": "10.22.0",and save - Apply the patch using the command output by the yarn patch command
- Rebuild