Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

6.0.1 functions.runWith is not a function #1616

Open
joalzamora opened this issue Sep 17, 2024 · 5 comments
Open

6.0.1 functions.runWith is not a function #1616

joalzamora opened this issue Sep 17, 2024 · 5 comments

Comments

@joalzamora
Copy link

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?

@google-oss-bot
Copy link
Collaborator

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.

@davie-robertson
Copy link

davie-robertson commented Sep 17, 2024

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 #1614

@alankent
Copy link

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.

@Fangh
Copy link

Fangh commented Sep 30, 2024

@JCcastagne
Copy link

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) => {
  (...)
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants