Can't deploy Firebase functions (Failed to fetch Run service undefined) - firebase

Can't deploy Firebase functions. I have two project aliases, it's working fine for the first project (dev), but not for the second (prod).
Whenever I write firebase deploy --only functions I get the following message
i deploying functions
i functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i functions: ensuring required API cloudbuild.googleapis.com is enabled...
i artifactregistry: ensuring required API artifactregistry.googleapis.com is enabled...
+ functions: required API cloudbuild.googleapis.com is enabled
+ artifactregistry: required API artifactregistry.googleapis.com is enabled
+ functions: required API cloudfunctions.googleapis.com is enabled
i functions: preparing codebase default for deployment
! functions: package.json indicates an outdated version of firebase-functions. Please upgrade
using npm install --save firebase-functions#latest in your functions directory.
! functions: Please note that there will be breaking changes when you upgrade.
i functions: Loaded environment variables from .env.prod.
! functions: You are using an old version of firebase-functions SDK (3.15.7). Please update
firebase-functions SDK to >=3.20.0
i functions: preparing functions directory for uploading...
i functions: packaged E:\FlutterProjects\pegasus\functions (218.61 KB) for uploading
Error: Failed to fetch Run service undefined

I had the same issue and it was fixed for me when installed the latest firebase tools
npm install -g firebase-tools

This was also fixed automatically by upgrading the version of firebase-tools using the command npm install -g firebase-tools.
You can add the --force flag if you encounter the below error
npm ERR! code EEXIST
npm ERR! path /usr/local/bin/firebase
npm ERR! EEXIST: file already exists
npm ERR! File exists: /usr/local/bin/firebase

You may also need to re-source your terminal. I checked my version after npm i -g firebase-tools and it still wasn't 11.18.0 but did a source ~/.zshrc and it fixed the issue.

You need to update your firebase-tools. Run npm install -g firebase-tools.

Make sure you execute npm install -g firebase-tools in the functions folder.

When you're using Firebase Tools with a version that is less than or equal to v11.18.0, you might encounter the following error:
Error: Failed to fetch Run service undefined
The first thing that you should take into consideration is to update to a version that is newer than or equal to v11.18.0. By the time I'm answering this question, the latest version is 11.20.0.
Furthermore, install the latest Firebase tools by using the following line of code in your terminal:
npm install -g firebase-tools --force
npm audit fix
P.S. It's also recommended to update Firebase Function to the latest available version which now it's 4.1.1.

Related

Unable to install Firebase

I am unable to install firebase tool.
> C:\Users\Mohit Saini>npm i -g firebase-tools
> npm WARN deprecated request#2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
> npm ERR! Unexpected end of JSON input while parsing near '...ePY2w==","shasum":"89'
firstly run npm cache clean --force to clear previous caches
after that run npm cache verify which will bring 0 bytes indicating all cache was cleared.
lastly run npm install -g firebase-tools
note: running the clean --force command will deletes all data from your cache folder.
When I search for the error message, this Github issue shows up: https://github.com/firebase/firebase-tools/issues/2215, which seems to indicate the problem can be fixed by running:
npm cache verify
If you get problems installing the CLI, and are not familiar enough with the environment to fix them, I'd recommend installing the standalone binary version of the Firebase CLI instead.

Unable to login Firebase with cli command

I'm trying to login to my Firebase account with cli command firebase login. I believe it should open browser and prompt me to login with my google account, but that doesn't seem to happen.
Instead, it's asking me to enter my email and password in the terminal. Once I enter my credentials, it throws the following error:
/usr/lib/node_modules/firebase-cli/node_modules/source-map-support/source-map-support.js:223
return '\n at ' + wrapCallSite(frame);
^ TypeError: CallSite method toString expects CallSite as receiver
How do I fix this as I want to deploy my app to Firebase?
I've had the same issue.
You're probably using firebase-cli instead of firebase-tools.
https://firebase.google.com/docs/cli#update-cli
firebase-cli has been deprecated years ago.
#mikeonline did you ever installed the Firebase tools/cli before on
your machine (before we launched v3 at Google IO) basically did you
have v2.2 previously installed perhaps?
firebase-cli has been deprecated a year ago and only installs v1. NPM
should have printed this message"
npm WARN deprecated firebase-cli#1.2.0: Use firebase-tools instead.
Both v2 and v3 can be installed with npm install -g firebase-tools but
by default the latest version (3.0.0) gets installed.
https://github.com/firebase/codelab-friendlychat-web/issues/22#issuecomment-220695413
Execute the below command
npm uninstall firebase-cli
npm uninstall firebase-tools
npm install -g firebase-tools --force

Package.json indicates an outdated version of firebase-functions

I have Cloud functions project and i moved the project from my old laptop to my new laptop.
I have installed everything that necessary. My problem is when i try firebase deploy it gives me that error:
! functions: package.json indicates an outdated version of firebase-functions.
Please upgrade using npm install --save firebase-functions#latest in your functions directory.
I did that i have been told, but still it gives me the same error.
What should i do? And how i direct the npm install to my functions directory?
You need to run sudo npm install --save firebase-functions#latest in your functions directory. Cannot be in any other directory.
In Flutter this will be in
/path_to_your_flutter_project/functions
Hope this helped someone
I had the same problem.
You just need to run npm install -g firebase-tools
npm install -g firebase-tools
/usr/local/bin/firebase -> /usr/local/lib/node_modules/firebase-tools/lib/bin/firebase.js
+ firebase-tools#7.0.0
That fixed my problem.
Update firebase-admin and make sure your root package.json file points to your functions folder

Firebase - Unable to serve local function after upgrading to 6.9.0

After upgrading firebase-tools from 6.8.0 to 6.9.0 my local function stopped working. I get below error message when calling it from my application:
λ firebase.cmd serve --only functions:upload
+ functions: Using node#12 from host.
+ functions: Emulator running at http://localhost:5001
i functions: Beginning execution of "upload"
! Error: Cannot find module 'package.json'
Require stack:
- C:\Users\MyLocalUsername\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:610:15)
at Function.Module._load (internal/modules/cjs/loader.js:526:27)
at Module.require (internal/modules/cjs/loader.js:666:19)
at require (internal/modules/cjs/helpers.js:16:16)
at verifyDeveloperNodeModules (C:\Users\MyLocalUsername\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:125:32)
at C:\Users\MyLocalUsername\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:457:26
at Generator.next (<anonymous>)
at C:\Users\MyLocalUsername\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:7:71
at new Promise (<anonymous>)
at __awaiter (C:\Users\MyLocalUsername\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:3:12)
! Your function was killed because it raised an unhandled error.
I have reinstalled node and npm entierly (including deleting %appdata% files), deleted all node_module files and reinstalled everything with npm ci but problem remains.
firebase.cmd is version 6.0.0
How do I continue? I could serve the very same function before upgrading, but now even if trying to downgrade using npm i firebase-tools#6.8.0 problem remains.
The function right now:
const functions = require('firebase-functions');
exports.upload = functions.https.onRequest((req, res) => {
console.log('Upload initiated')
return null;
});
I had the same problem after upgrading from firebase-tools 6.7.2 to 6.9.0
These steps worked for me to roll back to a previous version on Windows 10:
Uninstall the functions-emulator
Uninstall firebase-tools
Remove the functions-emulator config <== This is the step I didn't know about
Re-install a previous version of firebase-tools (6.7.2 or 6.8.0)
Detailed steps:
Switch nodejs version if you have multiple. I removed the functions-emulator and firebase-tools from all versions. Uninstalling needs to be done for each version separately.
nvm use 8.16.0
Uninstall the functions-emulator. More info: https://github.com/GoogleCloudPlatform/cloud-functions-emulator/wiki/Troubleshooting
npm uninstall -g #google-cloud/functions-emulator
Uninstall firebase-tools
npm uninstall -g firebase-tools
Delete the functions-emulator configuration folder found at 'C:\Users\yourusername\.config\configstore#google-cloud\functions-emulator'
Install a previous version of firebase-tools. Versions are listed at https://www.npmjs.com/package/firebase-tools
npm install -g firebase-tools#6.8.0
I believe you may only be able to use the functions-emulator with one nodejs version so if you install it with 8.16.0 then make sure you've switched to that version with '> nvm use 8.16.0' before you start testing cloud functions locally
Login to firebase
firebase login
In your project directory update the functions and admin packages
npm install firebase-functions#latest firebase-admin#latest --save
Start testing locally
firebase functions:shell
Or use
firebase serve
Note: Calling the functions-emulator directly with 'firebase emulators:start' won't work.
Follow this issue on github for updates: https://github.com/firebase/firebase-tools/issues/1258

Firebase config variables are not available error with deploying functions

When I am deploying Firebase functions without
admin.initializeApp(functions.config().firebase);
Firebase logs
Error: The default Firebase app does not exist. Make sure you call
initializeApp() before using any of the Firebase services.
But if I add that line I get error on deploy.
>firebase deploy --only functions
Error:
Error: Error occurred while parsing your function triggers. Please
ensure you have the latest firebase-functions SDK by running "npm i
--save firebase-functions#latest" inside your functions folder.
Error: Firebase config variables are not available. Please use the
latest version of the Firebase CLI to deploy this function.
I already did npm i --save firebase-functions#latest which haven't done anything. I am stuck and can't do anything right now because of this... I am down for any reinstalls if they could help just tell me some steps or hints and I would seek for the rest.
NPM and NodeJS versions are:
node -v
v8.9.1
npm -v
5.6.0
Edit. Installation with admin rights:
npm i --save firebase-functions#latest
npm WARN firebase-functions#0.8.1 requires a peer of firebase-admin#~5.8.1 but none is installed. You must install peer dependencies yourself.
npm ERR! path C:\Users\Telion\firebaseApps\project-name\functions\node_modules\firebase-admin\node_modules\grpc\node_modules\abbrev
npm ERR! code ENOENT
npm ERR! errno -4058
npm ERR! syscall rename
npm ERR! enoent ENOENT: no such file or directory, rename 'C:\Users\Telion\firebaseApps\project-name\functions\node_modules\firebase-admin\node_modules\grpc\node_modules\abbrev' -> 'C:\Users\Telion\firebaseApps\project-name\functions\node_modules\firebase-admin\node_modules\grpc\node_modules\.abbrev.DELETE'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
It actually appeared I was on npm version 5.5.1 but even after the update to 5.6.0 I got the exact same error.
There was a breaking change introduced in firebase-tools#3.17.x which requires your project to upgrade firebase-functions to the latest version.
However, firebase-functions#latest also requires firebase-admin#latest (at the time of writing this answer firebase-admin#5.11.0. Once all packages are upgraded, this problem should be solved.
Another alternative is to downgrade your global firebase-tools to 3.16.0, which lets you use older firebase-functions and firebase-admin packages.
I ran into the same issue in Ubuntu and this is how i solved it
Install firebase using : sudo npm install -g firebase-tools
Also make sure you launch using admin privileges e.g to login
sudo firebase login
You also need to update the node to at least 8.15.x. That detail is shown in the message.
Once I intalled that I had to do a firebase login command and after that you can run the firebase init hosting
Previously I was getting the error on firebase init hosting but after that node update, it went away.
Hope it helps.
For me, it worked for firebase-tools6.9.2.
The firebase-tools3.16.0 is completely depricated.

Resources