Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

It looks like you're trying to access functions.config().algolia but there is no value there

I am trying to run firebase emulators for cloud functions, but when I type firebase emulators:start, everytime I get this error Error

I tried setting up functions configuration too as suggested by => https://firebase.google.com/docs/functions/local-emulator . It generates .runtimeconfig.json file. But I am still getting the same error. enter image description here

Note that I am a complete beginner in cloud functions.

like image 618
Shrijan Regmi Avatar asked Aug 25 '20 04:08

Shrijan Regmi


5 Answers

I had the same issue and was able to fix it by saving my .runtimeconfig.json file with UTF-8 encoding instead of UTF-16 encoding.

The firebase functions:config:get > .runtimeconfig.json command seemed to save it with UTF-16 encoding by default, and the emulator does not like that for some reason.

If using VScode you can change to UTF-8 by clicking UTF-16 LE in the bottom right of the window. Then just hit save with encoding => UTF-8

change UTF-16 LE to UTF-8

like image 107
Johnnybib Avatar answered Nov 23 '22 17:11

Johnnybib


I had the same issue. The .runtimeconfig.json should be in the functions directory.

So you have to do cd functions and then firebase functions:config:get > .runtimeconfig.json.

like image 37
Sebastiaan Zwinkels Avatar answered Nov 23 '22 17:11

Sebastiaan Zwinkels


I think the part that is impacting you as well, is the TypeError: Cannot read property appid of undefined. As clarified in this issue on Github official repository, you need to run the command firebase functions:config:get > .runtimeconfig.json, after configuring your algolia.app_id - which relates to the second error that I mentioned - via the command firebase functions:config:set algolia.app_id="YOUR_APP_ID".

So, first, configure your app_id for your Algolia and once you have than that, run the command firebase functions:config:get > .runtimeconfig.json, so you have Algolia well configured in your Cloud Functions and the error is not faced anymore.

like image 25
gso_gabriel Avatar answered Nov 23 '22 19:11

gso_gabriel


As noted by others, make sure to run this command "inside" functions subdir or move the generated file there. firebase functions:config:get > .runtimeconfig.json and that the file has correct encoding.

To verify your functions are reading all configuration correctly, "temporarily" add this line to your code

functions.logger.warn(functions.config());

And start the functions emulator. You should see a json output with all the configuration that you have set before. if anything is missing you need to set again then deploy the functions and regenerate the .runtimeconfig.json for emulator.

like image 30
pref Avatar answered Nov 23 '22 17:11

pref


This is already mentioned in Firebase doc https://firebase.google.com/docs/functions/local-emulator#unix

Use the below command:

firebase functions:config:get > .runtimeconfig.json

If using Windows PowerShell, replace the above with:

firebase functions:config:get | ac .runtimeconfig.json
like image 44
Shashwat Sahu Avatar answered Nov 23 '22 17:11

Shashwat Sahu