Firebase - Unable to serve local function after upgrading to 6.9.0 - firebase

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

Related

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

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.

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 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.

Firebase: Cannot start emulator

functions: Cannot start emulator. Error: Cannot find module '#google-cloud/functions-emulator/src/config'
This is the error message I get when I try to run functions locally on Mac. My Firebase version is 3.16.0. I tried doing sudo npm install -g #google-cloud/functions-emulator as well. But still no use. Please help.
Solution is:
yarn global add firebase-tools
yarn global add #google-cloud/functions-emulator --ignore-engines
Working Solution!(OSX) None of the above worked for me. After a long struggle, I found the following solution.
cd my_project/functions
npm install #google-cloud/functions-emulator
Copy #google-cloud/functions-emulator folder generated inside node_modules.
cd /usr/local/lib/node_modules/#google-cloud && open .
Paste the functions-emulator folder here.
In your project's root directory, copy package.json inside functions/node_modules/#google-cloud/functions-emulator
cd /usr/local/lib && open .
Paste the package.json here.
npm install
Hurray! You are good to go. Now go back to your project's root directory and run.
sudo firebase serve --only hosting,functions
And the emulator should start normally.
Note: Do not run sudo npm install -g #google-cloud/functions-emulator since the files will be removed and reinstalled. This is where the installation fails and emulator fails to run.
Hope this helps!
The following worked for me.
npm uninstall -g firebase-tools && npm i -g firebase-tools
npm i --save #google-cloud/firestore
npm i --save #google-cloud/common-grpc
npm i -g #google-cloud/functions-emulator
npm i --save firebase-functions
current package.json snippet
"dependencies": {
"#google-cloud/common-grpc": "^0.5.3",
"#google-cloud/firestore": "^0.11.1",
"firebase-functions": "^0.8.1",
"firebase-admin": "5.8.1"
}
My system: Ubuntu 16.04.3
I had the same problem and the reason is that "#google-cloud/functions-emulator" is not installed in the 'npm global packages folder'.
In my case it happened because I installed firebase-tools globally using yarn, and I used it because when installing firebase-tools globally using npm I was getting an folder access error, which did not happen with yarn.
What I did to solve the problem was to follow these simple instruction from npm website to use a different folder for npm global packages (https://docs.npmjs.com/getting-started/fixing-npm-permissions).
Then I installed again with 'npm install -g firebase-tools' (without sudo) and it worked perfectly.
I had the same problem, using Ubuntu 17.10.
Note: You do not need to, and should not, use sudo for the installation.
I resolved this by performing the following:
Uninstall any previously attempted installed of the functions emulator.
npm uninstall -g #google-cloud/functions-emulator
and to make sure:
yarn global remove #google-cloud/functions-emulator
Delete all files in ~/.config/configstore/#google-cloud/functions-emulator. Note that there are some hidden files in this directory.
rm -rf ~/.config/configstore/#google-cloud/functions-emulator
Install nvm (node version manager) by following the instructions here:
https://github.com/creationix/nvm#install-script
Use nvm to install a specific version of node - at the time of writing, the Google Cloud Function Emulator (version 1.0.0-alpha.29) specifically requires 6.11.5.
nvm install 6.11.5
Install the Google Cloud Platform SDK:
https://cloud.google.com/sdk/
Reinstall the functions emulator:
npm install -g #google-cloud/functions-emulator
Start the emulator to verify installation has succeeded:
functions start
IMPORTANT: Subsequently, when attempting to create a function that can be tested locally or deployed to Google Cloud, you should use the firebase init functions command within your project, and allow this to install dependencies via npm. A walkthrough of creating a test function with Firebase can be found here:
https://firebase.google.com/docs/functions/get-started

Resources