firebase / quickstart-unity

Firebase Quickstart Samples for Unity
https://firebase.google.com/games
Apache License 2.0
819 stars 424 forks source link

Cloud functions not working with Quickstart project #1345

Closed xn1cklas closed 10 months ago

xn1cklas commented 11 months ago

[REQUIRED] Please fill in the following fields:

[REQUIRED] Please describe the issue here:

Actually, I ran into two errors, not sure if they are connected. If not, I can move one to a separate issue.

NPM installation failed

Following the instructions from quickstart-unity/functions/testapp/readme.md

Move to the `Assets/Firebase/Sample/Functions/.functions` subdirectory of
the sample.

cd Assets/Firebase/Sample/Functions/.functions

# Install all of the dependencies of the cloud functions
cd functions
npm install
cd ..

This does not work. THere is no functions in Assets/Firebase/Sample/Functions/.functions npm install doesn't work in neither of them, even though there are functionspackage.json they cannot be read by node/npm.

Error:

npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /Users/username/Directory/project-name/Assets/Firebase/Sample/Functions/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/Users/username/Directory/project-name/Assets/Firebase/Sample/Functions/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 

Unity cloud function exampleadd number not working

  Error: System.AggregateException: One or more errors occurred. (INTERNAL) ---> Firebase.Functions.FunctionsException: INTERNAL
  at Firebase.Functions.HttpsCallableReference.<CallAsync>b__9_0 (System.Threading.Tasks.Task`1[TResult] task) [0x00063] in <7a611edaa0f948979d1e886be7bbe8e0>:0 
  at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2[TAntecedentResult,TResult].InnerInvoke () [0x00024] in <130809ae6f984869a6663c878f16e3f3>:0 
  at System.Threading.Tasks.Task.Execute () [0x00000] in <130809ae6f984869a6663c878f16e3f3>:0 
   --- End of inner exception stack trace ---
---> (Inner Exception #0) Firebase.Functions.FunctionsException: INTERNAL
  at Firebase.Functions.HttpsCallableReference.<CallAsync>b__9_0 (System.Threading.Tasks.Task`1[TResult] task) [0x00063] in <7a611edaa0f948979d1e886be7bbe8e0>:0 
  at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2[TAntecedentResult,TResult].InnerInvoke () [0x00024] in <130809ae6f984869a6663c878f16e3f3>:0 
  at System.Threading.Tasks.Task.Execute () [0x00000] in <130809ae6f984869a6663c878f16e3f3>:0 <---

UnityEngine.Debug:Log (object)
Firebase.Sample.Functions.UIHandler:DebugLog (string) (at Assets/Firebase/Sample/Functions/UIHandler.cs:72)
Firebase.Sample.Functions.UIHandler/<>c__DisplayClass14_0:<AddNumbers>b__0 (System.Threading.Tasks.Task`1<Firebase.Functions.HttpsCallableResult>) (at Assets/Firebase/Sample/Functions/UIHandler.cs:109)
Firebase.Extensions.TaskExtension/<>c__DisplayClass4_1`1<Firebase.Functions.HttpsCallableResult>:<ContinueWithOnMainThread>b__1 ()
Firebase.Dispatcher/<>c__DisplayClass5_0`1<bool>:<RunAsync>b__0 ()
Firebase.ExceptionAggregator:Wrap (System.Action)
Firebase.Dispatcher:PollJobs ()
Firebase.Platform.FirebaseHandler:Update ()
Firebase.Platform.FirebaseMonoBehaviour:Update ()

Steps to reproduce:

  1. Forked the quickstart-unity repo
  2. Added the sample folder from the functions example
  3. followed the instructions step by step
google-oss-bot commented 11 months ago

This issue does not seem to follow the issue template. Make sure you provide all the required information.

AlmostMatt commented 10 months ago

Thanks for reporting this. It seems that several files like functionspackage.json were meant to be functions/package.json @paulinon submitted a fix for this, so you should be able to pull the latest version of the quickstart and then npm should detect the functions folder as a valid node project.

For your second issue, if the first issue prevented you from deploying the sample function, then it makes sense that addNumbers would have failed. The file .functions/functions/index.js defines a method named addNumbers, and after you have deployed this to your firebase project, when you run the testapp it will ask the server to run the addNumbers function, which will only work if it has already been deployed.

Feel free to re-open if the current fix was not sufficient.