[go: nahoru, domu]

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

Module '"firebase-functions/v1"' has no exported member 'onInit'. #1561

Closed
marcusicaro opened this issue May 2, 2024 · 5 comments
Closed
Labels
Needs: Author Feedback Issues awaiting author feedback

Comments

@marcusicaro
Copy link
marcusicaro commented May 2, 2024

Related issues

[REQUIRED] Version info

node: v18.18.0

firebase-functions:: ^4.7.0

firebase-tools:: ^12.7.0

firebase-admin:: 13.2.1

[REQUIRED] Test case

  const { GoogleGenerativeAI } = require('@google/generative-ai');
  const { defineSecret } = require('firebase-functions/params');
  const { onInit } = require('firebase-functions/v1');

  const apiKey = defineSecret('GOOGLE_API_KEY');

  let genAI;
  onInit(() => {
    genAI = new GoogleGenerativeAI(apiKey.value());
  })

[REQUIRED] Steps to reproduce

Just copy the example from the official documentation.

[REQUIRED] Expected behavior

To have a module named onInit

[REQUIRED] Actual behavior

TypeError: onInit is not a function
at Object. (~)
at Module._compile (node:internal/modules/cjs/loader:1256:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
at Module.load (node:internal/modules/cjs/loader:1119:32)
at Module._load (node:internal/modules/cjs/loader:960:12)
at Module.require (node:internal/modules/cjs/loader:1143:19)
at require (node:internal/modules/cjs/helpers:119:18)
at Object. (/home/marcus/Documents/monorepo/tarvos-web-serverless/functions/dist/src/lib/helpers/firebaseApiHelper.js:7:19)
at Module._compile (node:internal/modules/cjs/loader:1256:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)

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.

@google-oss-bot
Copy link
Collaborator

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

@ezequieltejada
Copy link

I've tried the same but with v2 without luck:

import {onInit} from "firebase-functions/v2/core";
...
const stripePrivateKey = defineString("STRIPE_PRIVATE_KEY");
const stripeWebhookSecret = defineString("STRIPE_WEBHOOK_SECRET");
...
let stripe: Stripe;
let STRIPE_WEBHOOK_SECRET: string;
onInit(() => {
  stripe = new Stripe(stripePrivateKey.value());
  STRIPE_WEBHOOK_SECRET = stripeWebhookSecret.value();
});
....

And I'm getting this error:
image

However if I hover the mouse over I get this:
image

@exaby73
Copy link
exaby73 commented May 17, 2024

You should be importing it directly from firebase-functions. So @ezequieltejada your code sample would be:

import {onInit} from "firebase-functions";
...
const stripePrivateKey = defineString("STRIPE_PRIVATE_KEY");
const stripeWebhookSecret = defineString("STRIPE_WEBHOOK_SECRET");
...
let stripe: Stripe;
let STRIPE_WEBHOOK_SECRET: string;
onInit(() => {
  stripe = new Stripe(stripePrivateKey.value());
  STRIPE_WEBHOOK_SECRET = stripeWebhookSecret.value();
});
....

Let me know if this fixes your issue

@exaby73 exaby73 added Needs: Author Feedback Issues awaiting author feedback and removed needs-triage labels May 17, 2024
@ezequieltejada
Copy link

I tried you suggestion and now it compiles, doesn't give an error. Thank you!!!

@exaby73
Copy link
exaby73 commented May 22, 2024

I'll close this issue as this is a problem with imports being incorrect initially :) Glad you were able to solve this. If you disagree with my closing and this issue is still reproducible even with the above imports, please let me know and I can reopen this isue following an investigation. Thank you

@exaby73 exaby73 closed this as not planned Won't fix, can't repro, duplicate, stale May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Author Feedback Issues awaiting author feedback
Projects
None yet
Development

No branches or pull requests

4 participants