Firebase deploy: Missing expected firebase config value databaseURL - javascript

I'm trying to deploy my first function with firebase cloud functions.
I deployed the standard function "helloWorld" without problem, but then, when I added this:
const admin = require("firebase-admin");
admin.initializeApp();
firebase deploy didn't work anymore and caused this error:
Missing expected firebase config value databaseURL, config is actually{"projectId":"PROJECT-ID","storageBucket":"PROJECT-ID.appspot.com","locationId":"europe-west"}
If you are unit testing, please set process.env.FIREBASE_CONFIG
How can I set config or the value of databaseURL? I don't find anywhere the file where these things are written... I also looked in documentation but I didn't find anything useful
I tried also with
admin.initializeApp(process.env.FIREBASE_CONFIG);
but this give me this error:
Error: Error occurred while parsing your function triggers.
Error: Invalid Firebase app options passed as the first argument to initializeApp() for the app named "[DEFAULT]". Options must be a non-null object.

It looks like you're being affected by a change that was made a few months ago where the databaseURL is no longer auto-created when you create a new project.
If that is the case, you you can force the databaseURL to be generated by going to the Realtime Database panel in the Firebase console. If this indeed fixes the problem, it might be worth filing a bug report with the Firebase support team.

It looks like you don't have a default database created. Visit your firebase console and create at least one real-time database.
You can explicit select a database instance with functions.database.instance() View Docs

Related

How to pull data from the Directus database to the site?

I created a database in Directus. I created a separate project for the site, where I will add data. Installed # directus / sdk.
image
But when importing, I get an error
Uncaught SyntaxError: Cannot use import statement outside a module
this is my code
import { Directus } from '#directus/sdk';
const directus = new Directus('https://api.example.com/');
await directus.auth.login({
email: 'admin#example.com',
password: 'pass',
});
const articles = await directus.items('articles').readMany();
console.log({
items: articles.data,
total: articles.meta.total_count,
});
How do I fix this error?
Is it correct to create a separate project for the site? Or could it be done in the same place as the database?
TLDR; The issue faced is does not appear to be an issue with Directus.
There are three different pieces of software/code that that you should be aware of.
Database.
Directus Install.
Your App.
These are three different things, make sure you're clear on the difference. The database will be stored in your database of choice, MySQL, Postgres etc... Directus only connects to this and it will remain should you decide to stop using Directus for any reason.
You will need to install Directus in one location. You will then need to write your application in another location, where you may use the SDK for easy Directus API usage within your app.
It is correct (as you asked) to have your application as a separate "project".
The reason you are getting the error Cannot use import statement outside a module is not related to Directus. This is a common error when you are building or compiling your application incorrectly (Not ES6) therefore I cannot provide much support to you.
Here are some helpful debugging resources:
https://www.google.com/search?q=cannot+use+import+statement+outside+a+module
"Uncaught SyntaxError: Cannot use import statement outside a module" when importing ECMAScript 6
https://exerror.com/uncaught-syntaxerror-cannot-use-import-statement-outside-a-module-when-importing-ecmascript-6/

ApplicationInsightsTelemetryClient not logging bot identifiers

I'm using the JavaScript version of the botframework. I've followed the documentation to enable telemetry logging in Application Insights. When I access the logs I can see that custom events are being logged.
The issue is that the bot specific identifiers, such as user_Id, session_Id and conversation_Id are not being logged. This can be seen in the screen capture below
In the applicationInsightsTelemetryClient.js file there is a function called addBotIdentifiers. As far as I can tell, it is this function that is responsible for adding the bot specific identifiers.
The first lines of the function look like this:
function addBotIdentifiers(envelope, context) {
if (context.correlationContext && context.correlationContext.activity) {
Inspecting this function shows that the context argument is always null.
This leads me to my questions.
Why is it null?
Any suggestions on what I need to do to have it set appropriately?
Update
In digging into this further it appears the code starting at line 26 in the applicationInsightsTelemetryClient.js file isn't being called. Could this be the cause of the missing context later on in the addBotIdentifiers function?
Looks like the documentation has a missing line in step 7. We will correct the document ASAP. Meanwhile, please add the below in your index.js following https://github.com/microsoft/BotBuilder-Samples/blob/main/samples/javascript_nodejs/21.corebot-app-insights/index.js#L113
// Enable the Application Insights middleware, which helps correlate all activity
// based on the incoming request.
server.use(restify.plugins.bodyParser());
Further investigation has shown what the issue was. It's not immediately obvious.
I compared the code in my index.js file with the one in the 21.corebot-app-insights BotBuilder sample.
Note that the setup of the Restify server happens after the creation of the adapter bot adapter. It is also after the configuration of the main dialog and the middleware.
In my code the setup of the Restify server and the bot adatper / dialogs was intermingled. This appears to have been the cause of the problem.
The main lesson here for me, and for anyone who stumbles across this post later, is that the setup of the Restify server should be at the end of the index.js file. To ensure all of the bot framework is setup first.

Unable to get documents for a collection in fire cloud firestore

This really feels completely strange to me. It worked perfectly fine almost 1 week back but now it keeps throwing error:
error.ts:166 Uncaught (in promise) FirebaseError: Document name "["projects/anilproject12001/databases/(default)/documents/1234/J9a7qpOGHjfCBoXzRu6P"]" lacks "projects" at index 0.
I have configured a very simple db structure, which looks like below:
My cloud firestore screenshot
And my code looks like below:
firebase.initializeApp(config);
// Get a reference to the database service
//var db = firebase.database().ref('test1');
var db = firebase.firestore();
db.collection("1234").doc().get().then(function(){console.log('success!');})
Any idea why is this happenning? I have deleted the previous DB and made the simplest of entries for debugging purpose.
Is there something that I am missing in configuration?

Im getting this error: firebase.INTERNAL.registerAppHook is not a function, why?

I am trying to setup firebase web client messaging.
I couldn't find this error mentioned anywhere
I have my firebase account and basic firebase code in my app.
Authentication seems to be working, I had some errors about that and fixed them.
Now I'm trying to retrieve some info from the DB but I'm getting this error.
Yes, the DB has info in it.
Here is my code ( without the auth data, yes I have that info from my account and yes I have the container with that id setup as well )
This is js inside some PHP, seems to be loading correctly with no errors
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
const preObject = document.getElementById("object");
const dbRefObject = firebase.database().ref().child("object");
dbRefObject.on("value", snap => console.log(snap.val()));
I am getting this error and I couldn't find info about it anywhere:
TypeError: firebase.INTERNAL.registerAppHook is not a function
I was expecting info to be retrieved and shown on site
The error is arising from the line:
<script defer src="https://www.gstatic.com/firebasejs/3.1.0/firebase-auth.js"></script>
Remove it and try again!

Firebase function not fetching config variable

I'm trying to write a firebase function to send a transactional e-mail with SendGrid whenever it gets triggered by a HTTP request, but at the moment I'm having real difficulty getting the function to be able to access the configuration variables that I've set with the sendgrid key which is obviously a real problem...
I've set the config variable with the below command:
$ firebase functions:config:set sendgrid.key="KEY_HERE"
When I run firebase functions:config:get to list all the config values, it returns the correct value in the terminal:
{
"sendgrid": {
"key": "KEY_HERE"
}
}
But when I try to access it from my function (tried with both TypeScript & Vanilla JS setups), functions.config() just returns an empty object.
Has anyone encountered & solved this issue before, or am I doing something wrong? In either case, if anyone could give me a pointer then that'd be much appreciated!
Edit the first
I have deployed the function, and called it while hosted and looking at the logs, you can see the correct values. However, I still see the problem when I call the function when served locally on my machine for testing, which is a problem as I'd like to not have to deploy a function just to see if it works...

Categories

Resources