react-native-firebase: TypeError: undefined is not an object - react-native-firebase

Almost looks like uploading to storage should work but I end up with this error:
TypeError: undefined is not an object (evaluating '_reactNativeFirebase.RNFirebase.storage'
I'm not sure what exactly this means—does it think that the native module is undefined or something?
I've tried two ways to get the storage instance:
import firebase from "react-native-firebase";
// attempt 1
const storage = firebase.initializeApp(config.firebase[Platform.OS], "myApp").storage();
const storage = firebase.storage();
And I put the file into firebase like so:
// `blob` is retrieved by calling `fetch(videoUri)`
storage.put(videoUri, {contentType: blob.data.type});
After that put call occurs, the UploadTask is created but rather than uploading that error gets thrown.
The library already has react-native link called on it, and other RNFirebase features like authentication are working already.
Any sugggestions? Thanks in advance!

Related

Firebase cloud messaging service worker issue (NextJS)

An error occurred while retrieving token.
FirebaseError: Messaging: We are unable to register the default service worker. SyntaxError: Unexpected token '{'. import call expects exactly one argument. (messaging/failed-service-worker-registration).
f —_app-6e5ce7543176b121599c.js:1:8509
create — _app-6e5ce7543176b121599c.js:1:8994
(anonymous function) —_app-6e5ce7543176b121599c.js:1:639312
asyncFunctionResume
(anonymous function)
promiseReactionJobWithoutPromise.
promiseReactionJob
I am getting fcm token from localhost. But the problem occurred when I try to build my next project and start or after deploying to the server.
I tried several solution from various sources.
Basically i was getting error because of new file structure.
import "firebase/compat/messaging";
import firebase from "firebase/compat/app";
this is the new version import structure.

Multiple errors when importing nodemailer in nextjs API

I am trying to have an API endpoint pages/api/sendEmail that uses nodemailer to send an email, but for some reason I get the error Can't resolve 'fs' when I try to use nodemailer with let nodemailer = require('nodemailer'). I have seen multiple posts about this always saying that this is due to the fact that I am trying to execute this in the frontend, but I am doing it in the API. I have also seen posts like this one and tried the fixes by modifying next.config.js, but after all the fixes this new error appeared:
Uncaught TypeError: util__WEBPACK_IMPORTED_MODULE_3__.TextEncoder is not a constructor
What I don't understand here is why can't I use the package in the API, since it is executed on the backend. I have seen multiple tutorials like this one that do the exact same thing.

How to check if Firebase Function has already been initialized

Just in case its important, this is how I am importing the functions stuff
import * as functions from "firebase-functions";
import admin = require("firebase-admin");
I am currently using the below code to check if the firebase function has already been initialized:
if (admin.apps.length === 0) {
admin.initializeApp();
} else {
functions.logger.log("App already initialized");
}
I got this code from: How to check if a Firebase App is already initialized on Android
My problem is that this doesn't seem to be checking if the app has already been initialized because I see the log from the else statement but immediately after I see the error log that the default Firebase app does not exist.
If I call admin.initializeApp(); it works, but only sometimes, other times it would tell me that
"Unhandled error FirebaseAppError: The default Firebase app already exists. This means you called initializeApp() more than once without providing an app name as the second argument. In most cases you only need to call initializeApp() once"
What is the correct way to see if the app has already been initialized?
I am not sure if the below is important but here goes:
I have my functions in separate files, to import the files into the index.ts file I:
Import the function:
import checkPayment = require("./checkPayment");
I'm not sure how to define what this is:
exports.checkPayment = checkPayment;
Perhaps I am importing the other functions incorrectly.
Thank you for your time.

Firebase | Getting error on fetching RemoteConfig values on functions.pubsub.schedule onRun

Normally we can fetch data from RemoteConfig normally in Firestore document triggers but in Pubsub schedule listener below code getting error:
let config = admin.remoteConfig();
const template = await config.getTemplate();
Error: Version update time must be a valid date string
The problem has been solved on firebase-admin 9.6.0 version or above.

While deploying index.ts, firebase function call in global scope requires only string literal

This two calls are failed:
const client = algoliasearch(functions.config().algolia.app_id, functions.config().algolia.admin_id);
const client = algoliasearch(process.env.app_id, process.env.admin_id);
Error: Error occurred while parsing your function triggers.
AlgoliaSearchError: Please provide an application ID. Usage:
algoliasearch(applicationID, apiKey, opts)*
But this one, which requires hard coded api keys is ok:
const client = algoliasearch('APP_ID', 'ALGOLIA_ADMIN_KEY');
How can I avoid hardcoded way of initializing algolia client?
Deploy mechanics checks if functions.config().algolia.app_id and admin_key are filled while deploying. It is good feature!!! But messages (Error occurred while parsing your function triggers.) don't allow to understand that in deploying (aka compile) time.

Resources