Firebase config variables are not available error with deploying functions - firebase

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.

Related

How to install firebase using npm package manager?

I know there are a lot of questions on stackoverflow and other sites about this, but despite all the answers given I couldn't solve my problem. For a while I have been trying to install firebase in my MERN Stack project from the command npm i firebase --save . Despite this I still get the following errors:
npm i firebase --save
npm ERR! code ENOTFOUND
npm ERR! syscall getaddrinfo
npm ERR! errno ENOTFOUND
npm ERR! network request to http://registry.npmjs.org/firebase failed, reason: getaddrinfo ENOTFOUND your-proxy-url
npm ERR! network This is a problem related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly. See: 'npm help config'
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\user\AppData\Local\npm-cache\_logs\2022-06-15T22_23_35_935Z-debug.log
After multiple searches on the Internet, I executed the following command then, npm clear cache --force npm clean cache --force but without success. I even tried this command npm i firebase --force unfortunately I get the same errors. I even copy-pasted the node_modules firebase package from another project where I had managed to install it and copied the following line into my package.json file "firebase": "^9.8.2", so that npm recognizes this package, unfortunately npm didn't recognize it because when I run I always get the same missing module errors related to firebase. I do not really know what else to do.
I found the solution on this url which is
npm config set registry http://registry.npmjs.org/
this will cause npm to use http instead of https. This means that npm will no longer be secure and will download without performing a prior check to know if I am on the right site. It is possible that it is my ISP that is blocking my connection to this site because I do not use a proxy.

Error 404 when installing dependencies for firebase functions

I'm trying to intall the following
npm install --save express body-parser firebase functions-helper
but I keep receiving these errors
npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/functions-helper - Not found
npm ERR! 404
npm ERR! 404 'functions-helper#latest' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\admin\AppData\Roaming\npm-cache\_logs\2020-07-13T12_53_21_822Z-debug.log
So far I tried doing this
npm clean cache
upgrade node to latest version but I still get the same errors
It's telling your you are trying to install a package that doesn't exist, I cannot find any package called functions-helper, did you mean firebase-functions-helper
There is no module called "functions-helper". If you are writing Cloud Functions using the Firebase tools, you will need to install the module called "firebase-functions", as described in the documentation.

Connecting Firebase to an React Native App that's using Expo

I am currently trying to connect Firebase to my React Native app that uses Expo. Im currently using this guide: https://docs.expo.io/guides/using-firebase/?fbclid=IwAR0c7g8a-005utr_ROomb_k3ptlAHel3kq004AtFbNkV9iWREeapzR0Dabg and it lead me to the github "Firebase JS SDK". I downloaded the whole github repo (https://github.com/firebase/firebase-js-sdk) and like tried following the instructions on the github such as downloading node, yarn, and java but I am confused on what to do next with the downloaded repo. I have tried running the command "npm install" to try and install the dependencies but I get this error:
npm WARN deprecated tslint#6.1.2: TSLint has been deprecated in favor of ESLint. Please see https://github.com/palantir/tslint/issues/4534 for more information.
npm WARN deprecated request#2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated request#2.88.0: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated core-js#2.6.11: core-js#<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js#3.
npm WARN deprecated resolve-url#0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated urix#0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated chokidar#2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
npm WARN deprecated mkdirp-promise#5.0.1: This package is broken and no longer maintained. 'mkdirp' itself supports promises now, please switch to that.
npm WARN deprecated fsevents#1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
npm ERR! Unexpected end of JSON input while parsing near '...cMP/3jKIr36/huSPHVVgD'
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Ban-Jian\AppData\Roaming\npm-cache\_logs\2020-05-19T23_15_25_175Z-debug.log
And when I run the command: "yarn build" I get this error:
lerna ERR! yarn run build exited 2 in '#firebase/firestore'
lerna ERR! yarn run build stdout:
$ tsc -m es2015 --moduleResolution node scripts/*.ts
error TS6053: File 'scripts/*.ts' not found.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
lerna ERR! yarn run build stderr:
error Command failed with exit code 2.
lerna ERR! yarn run build exited 2 in '#firebase/firestore'
lerna WARN complete Waiting for 4 child processes to exit. CTRL-C to exit immediately.
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
I guess my question is: How do I properly set up the SDK I downloaded from the github?

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

Resources