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

6.0.1 functions.runWith is not a function

Open joalzamora opened this issue 1 year ago • 6 comments

Related issues

[REQUIRED] Version info

upgrade from ^5.1.1 to ^6.0.1

node:

20

firebase-functions: ^6.0.1

firebase-tools: 13.15.2

13.5.2

firebase-admin: ^11.8.0

[REQUIRED] Test case

[REQUIRED] Steps to reproduce

Execute the following command npm install --save firebase-functions@latest

and when I run the code I get the following error

TypeError: functions.runWith is not a function

A sample code is:

const functions = require('firebase-functions');

exports.newAccount = functions .runWith({ memory: '256MB', maxInstances: 1, }) .auth.user().onCreate(async (user) => { const email = user.email; const subject = "Welcome"

    try {
        console.log("A new user account has been created")
    	await sendWelcome(email,subject);
    } catch (error) {
    	console.error('Error sending email:', error.message);
    }

});

[REQUIRED] Expected behavior

[REQUIRED] Actual behavior

TypeError: functions.runWith is not a function

Were you able to successfully deploy your functions?

joalzamora avatar Sep 17 '24 01:09 joalzamora

I found a few problems with this issue:

  • I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
  • This issue does not have all the information required by the template. Looks like you forgot to fill out some sections. Please update the issue with more information.

google-oss-bot avatar Sep 17 '24 01:09 google-oss-bot

There has been (what I consider to be an undocumented) breaking change in firebase-functions.

You now need to specify V1 on your import const functions = require('firebase-functions/v1');

see https://github.com/firebase/firebase-functions/issues/1614

davie-robertson avatar Sep 17 '24 08:09 davie-robertson

In case of use to anyone else who comes across this thread (like me!), I found the migration docs from v1 to v2 and so no longer use runWith() to pass in secrets.

const {onRequest} = require('firebase-functions/v2/https');

exports.readGoogleDoc = onRequest({
    secrets: [googleApiCredentials]
  }, async (req, res) => {

So I don't need the runWith() function - its now the first argument to the v2 onRequest() function.

alankent avatar Sep 30 '24 07:09 alankent

The doc is here : https://firebase.google.com/docs/functions/2nd-gen-upgrade#set_runtime_options

Fangh avatar Sep 30 '24 14:09 Fangh

In case of use to anyone else who comes across this thread (like me!), I found the migration docs from v1 to v2 and so no longer use runWith() to pass in secrets.

const {onRequest} = require('firebase-functions/v2/https');

exports.readGoogleDoc = onRequest({
    secrets: [googleApiCredentials]
  }, async (req, res) => {

So I don't need the runWith() function - its now the first argument to the v2 onRequest() function.

Thank you, @alankent

For me, it was outside of my function at the bottom of my code, I had declared my runWith params, which seemingly no longer works.

Old code:

export const myFunction = onRequest(async (req, res) => {
(...)
}

myFunction.runWith({
  invoker: 'private' // Set the invoker to 'private'
})

Newcode:

export const transcribeAudio = onRequest(
  {
    invoker: 'private' // Set the invoker to 'private'
  },
  async (req, res) => {
  (...)
})

JCcastagne avatar Oct 04 '24 18:10 JCcastagne

Thanks @alankent - I think a resolution to this would be to clearly document this change where possible in firebase-functions.

This should probably have been added to the changelog. I will raise this with the team to see how we can make sure it's clearly documented.

cabljac avatar Dec 17 '24 14:12 cabljac