firebase-functions icon indicating copy to clipboard operation
firebase-functions copied to clipboard

Upgrading Firebase-Functions from firebase-functions v4.3.1 to v6.0.1 cause gen 1 functions triggers to be undefined.

Open dual-x-tech opened this issue 1 year ago • 5 comments

Related issues

[REQUIRED] Version info

node: v20.17.0

firebase-functions: 6.0.1

firebase-tools: 13.18.0

firebase-admin: 12.5.0

npm 10.8.2

[REQUIRED] Test case

[REQUIRED] Steps to reproduce

Upgrade firebase-admin to v12.5.0 and firebase-functions to v6.0.1

Try to deploy this basic code in parenthesis " const functions = require('firebase-functions'); const admin = require('firebase-admin');

admin.initializeApp();

exports.helloWorld = functions.https.onRequest((req, res) => { res.send('Hello from Firebase Functions!'); });

exports.sendWelcomeEmail = functions.auth.user().onCreate((user) => { console.log(sendWelcomeEmail New user created: UID - ${user.uid}); // Add your email sending logic here return null; // Always return a value from a Cloud Function }); "

},

[REQUIRED] Expected behavior

Expect the function to deploy without issue.

[REQUIRED] Actual behavior

 TypeError: Cannot read properties of undefined (reading 'user')
Error: Functions codebase could not be analyzed successfully. It may have a syntax or runtime error

Were you able to successfully deploy your functions?

No, const functions = require('firebase-functions') in version 6.0.1 of firebase functions makes functions.auth.user() undefined

dual-x-tech avatar Sep 21 '24 06:09 dual-x-tech

use const functions = require('firebase-functions/v1');

AmilKey avatar Sep 23 '24 11:09 AmilKey

same issue here, auth is missing after updating to 6.0.0

CleanShot 2024-09-24 at 16 08 20@2x

ekremcet avatar Sep 24 '24 13:09 ekremcet

use const functions = require('firebase-functions/v1');

Tried this approach and it did not work.

  1. Downgrading using npm install [email protected]
    npm install [email protected]

  2. removing my node_modules folder and package_lock.json file

  3. run npm install

  4. then deploying the functions again worked for me.

dual-x-tech avatar Sep 24 '24 23:09 dual-x-tech

https://github.com/firebase/firebase-functions/issues/1614#issuecomment-2351811628

davie-robertson avatar Sep 25 '24 06:09 davie-robertson

same

AntonioArroyave avatar Oct 04 '24 19:10 AntonioArroyave

use const functions = require('firebase-functions/v1');

Tried this approach and it did not work.

  1. Downgrading using npm install [email protected] npm install [email protected]
  2. removing my node_modules folder and package_lock.json file
  3. run npm install
  4. then deploying the functions again worked for me.

Yes, the /v1 approach did not work but your the other suggestion of yours worked, thanks.

abdulloooh avatar Oct 30 '24 11:10 abdulloooh

Good afternoon, i also have the same issue, fresh install from today. Downgraded and it works . Thank you :)

UPDATE : tested this from comment of @davie-robertson https://github.com/firebase/firebase-functions/issues/1622#issuecomment-2373170560 and it works too with the latest version👍🏼

import functions from 'firebase-functions/v1'

export const onUserCreate = functions.auth.user().onCreate((user) => {
  console.log(user);
});

alamparelli avatar Oct 31 '24 16:10 alamparelli

I got it working by doing

import { auth } from "firebase-functions/v1"
export const onDeleteAccount = auth.user().onDelete(async function (user) {

slk333 avatar Nov 09 '24 15:11 slk333

Since a solution has been proposed and the documentation reflects the '/v1' pattern, I'm going to close this issue. However, if you find any issues with the current documentation, feel free to open a new issue.

CorieW avatar Feb 20 '25 14:02 CorieW