Firebase hosting doesn't let me deploy bc firebase-functions is outdated - firebase

functions: package.json indicates an outdated version of firebase-functions.
Please upgrade using npm install --save firebase-functions#latest in your functions directory.
=== Deploying to 'zootopia-mysite'...
i deploying functions, hosting
Running command: npm --prefix "$RESOURCE_DIR" run lint
> functions# lint /Users/zootopia/functions
> eslint .
✔ functions: Finished running predeploy script.
Error: There was an error reading functions/package.json:
Engines field is required but was not found in functions/package.json.
To fix this, add the following lines to your package.json:
"engines": {
"node": "10"
}
I've also tried to upgrade with npm install --save firebase-functions#latest and it still gives me the same error.

Your local project apparently works with both Firebase Hosting and Cloud Functions. The error message is telling you that the Cloud Functions deployment is failing, which doesn't have anything do with Firebase Hosting yet.
If you are trying to follow the advice of the output here, you're going to have to change to the "functions" folder and run the npm commands to upgrade the old modules and make any other changes to package.json.

Related

Firebase Next.js Hosting: Unable to find 'esbuild'

I'm trying to use Firebase's new Next.js support for Hosting (see https://firebase.google.com/docs/hosting/nextjs) but I'm getting a weird error when I try to deploy. (Everything runs correctly in the local emulator suite, btw)
Screenshot of Console output with error
When I try to run firebase deploy --only hosting,functions -m "testing out next.js support" I'm getting the error Unable to find 'esbuild'. Install it into your local dev dependencies with 'npm i --save-dev esbuild''. I've already added esbuild to my dev dependencies, and it seems to be installed correctly. My project uses yarn, not npm, but for the sake of testing I tried install it with npm like the error suggested, but that didn't work either.
Has anyone used Firebase Next.js hosting or figured it out since they've released it? The documentation on that page I linked above is... not great.
Make sure that you are using the latest Firebase Tools as per the documentation: "Firebase CLI version 11.14.2 or later".
Run npm install -g firebase-tools to update your version.

Deploy a SSR Nuxt 2 application on firebase

I have some troubles deploying a Nuxt 2.4 application on Firebase.
I tried these 2 tutorials but they seem outdated:
https://www.youtube.com/watch?v=ZYUWsjUxxUQ
https://github.com/davidroyer/nuxt2-ssr-firebase
With the first tutorial, I could make my app working on local (after few hours and with a lot of modifications for babel integration) but I never could serve or deploy it. I thought the tutorial was old and manipulations can't be exactly done like the guy did.
With the second tutorial, I cloned the repository to try to deploy the example. I had to change 2 things : install Node 8 instead of Node 10 and upgrading firebase-admin to the last version in prod/server dir. Here is what I got:
npm run setup is ok
npm run dev is ok and the project works fine
npm run build is ok
npm run serve fails.
First I got this error :
The Cloud Functions emulator requires the module "firebase-admin" to be version >7.0.0 so your version is too old. You can probably fix this by running "npm install firebase-admin#latest" in your functions directory.
Indeed, the version configured in package.json is the 5.13. I did the update from the prod/server dir, and I get the 8.0.0.
And then I got a different error about gRPC :
Error: Failed to load gRPC binary module because it was not installed for the current system
Expected directory: node-v57-darwin-x64-unknown
Found: [node-v64-darwin-x64-unknown]
This problem can often be fixed by running "npm rebuild" on the current system
I tried npm rebuild as mentionned, without success.
npm run deploy fails.
I get this trace:
i deploying functions, hosting
i functions: ensuring necessary APIs are enabled...
✔ functions: all necessary APIs are enabled
i functions: preparing prod/server directory for uploading...
Error: Error parsing triggers: Cannot find module 'acorn'
Try running "npm install" in your functions directory before deploying.
Of course, I tried the npm install from prod/server dir, but nothing changed.
Is there somewhere i can find a tutorial that can help me deploy my SSR app to firebase ? Thanks in avdance !
EDIT 1 :
After a few modifications on my package.json
upgrading firebase-functions and express to the latest versions
downgrading firebase-admin to the 7.0.0 version
adding acorn
I can serve and deploy but I get a "504 gateway time-out" webpage when I call the URL....
Have you tried to run npm install grpc inside functions folder?

Firebase function issue?

i functions: Preparing to emulate functions.
Warning: You're using Node.js v8.10.0 but Google Cloud Functions only supports v6.11.5.
⚠ functions: Failed to load functions source code. Ensure that you have the latest SDK by running npm i --save firebase-functions inside the functions directory.
⚠ functions: Error from emulator. Error parsing triggers: Cannot find module '/home/developer/Development/host2/functions'
Try running "npm install" in your functions directory before deploying.
We are new in firebase function , How to solve this issue ?
In many cases, new features and bug fixes are available only with the latest version of the Firebase CLI and the firebase-functions SDK. It's a good practice to frequently update both the Firebase CLI and the SDK with these commands inside the functions folder of your Firebase project:
npm install -g firebase-tools
npm install firebase-functions#latest firebase-admin#latest --save
visit: https://firebase.google.com/docs/functions/get-started
I don't know if my problem was the same as your, but for further reference I will post my solution.
In my case, I was using TypeScript instead of JavaScript, so the code needed to be compiled before run firebase serve.
In your Firebase app directory:
$ cd functions/
$ npm run-script build
$ cd ..
$ firebase serve
The last command maybe need super user permission, so sudo firebase serve.
Optionally you can run npm run-script lint before npm run-script build to check for possible errors if you are using tslint.
In my case the solution was :
1 - Reinstall Node ( version 10.15.0 ). After download node-v8.11.2-x64.msi from node.org
2 - Reinstall firebase-tools ( npm install firebase-tools -g )
3 - Clear cache ( npm cache clear --force )
I was having this problem too. I can't explain how, but it turns out that my firebase.json was not correct. Check the functions section of it and make sure it looks like this:
"functions": {
"source": "functions"
},
Found this SO answer: How to deploy functions from other directory than '/functions'?

TypeScript error when trying to deploy Firebase Function

I just created a firebase app and written my functions in typescript
import * as functions from 'firebase-functions'
export const onStatementUpload = functions.storage.object().onFinalize(obj => {
console.log('obj finalize', obj)
})
But on deployment:
src/index.ts(10,61): error TS2339: Property 'onFinalize' does not exist on type 'ObjectBuilder'.
I tried to install #types/firebase-functions but theres no such thing. How do I resolve this?
I was running into this issue as well and solved it by upgrading to the latest versions of firebase-functions, firebase-admin, and firebase-tools which added the onFinalize method (which wasn't available in previous versions).
# Make sure you're in your `functions` (or equivalent) directory
$ npm install firebase-functions#latest firebase-admin#latest --save
$ npm install -g firebase-tools
Then try redeploying the app:
$ firebase deploy --only functions

`firebase deploy` with CLI tools 3.17.0 gives "Error: Firebase config variables are not available"

Full error dump:
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.
at init (/Users/dougstevenson/work/google/firebase/functions/tmp/functions/node_modules/firebase-functions/lib/config.js:51:15)
at Object.config (/Users/dougstevenson/work/google/firebase/functions/tmp/functions/node_modules/firebase-functions/lib/config.js:29:9)
at Object.ref (/Users/dougstevenson/work/google/firebase/functions/tmp/functions/node_modules/firebase-functions/lib/providers/database.js:75:33)
at Object.<anonymous> (/Users/dougstevenson/work/google/firebase/functions/tmp/functions/lib/index.js:9:32)
at Module._compile (module.js:660:30)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
at Module.require (module.js:604:17)
With firebase-tools (the Firebase CLI) version 3.17.0, it's required to use the latest firebase-functions (version 0.8.1) and firebase-admin (version 5.8.1) SDKs. Update them by running this command from the functions folder:
npm install firebase-functions#latest firebase-admin#latest
After this, a deploy should succeed.
EDIT: This bug was fixed in CLI version 3.17.1. A similar bug appears also when running the emulator with the CLI, and that was fixed in 3.17.3.
To fix this I needed to run from the root path of your firebase functions folder:
npm update -g firebase-functions;
run it again..
npm update -g firebase-functions;
Then update the node_modules within your functions directory per above advice
cd functions;
npm install firebase-functions#latest firebase-admin#latest;
Note: Interestingly NPM complained the install of both packages was invalid, even after running install again. However executing a firebase deploy --only functions worked perfectly.
Incidentally, my simple deploy shortcut script may come in handy for those who don't like working in one big index.js file:
#!/bin/bash
(cd functions/; cat header.js get*.js process*.js set* > index.js; );
firebase deploy --only functions
say "fire base deploy done";

Resources