-
-
Notifications
You must be signed in to change notification settings - Fork 70
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
Edge runtime v1.2.18 fails to import firebase-admin with Identifier '__f$' has already been declared
#82
Comments
Ah it seems I'm still blocked by #44 anyway, the edge runtime still becomes completely unresponsive after any error. |
I think this could've been fixed by #74. I just ran the following piece of code in latest main
and it worked properly, logging:
It also seems some of the issues with the module loader is solved. CC @laktek |
@evelant We just rolled out a CLI update. Could you check if you experience the same with 1.61.1 ? Thanks! |
@andreespirela yes this error still happens with 1.61.2 unfortunately. |
@evelant Do you call a specific function from |
@laktek I only use the firebase SDK in development so I can auth against the firebase emulators. Here is the totality of the code that uses the firebase SDK. let hasInitialized = false
/**
* call firebase.initializeApp with credentials so we can verify the firebase auth token is legit
*/
const initFirebaseApp = async () => {
const firebase = (await import("https://esm.sh/[email protected]?bundle&target=deno&no-check")).default
if (hasInitialized) return firebase
hasInitialized = true
if (Deno.env.has("FIRESTORE_EMULATOR_HOST") && Deno.env.has("FIREBASE_AUTH_EMULATOR_HOST")) {
console.log(`initializing firebase app with emulators`)
firebase.initializeApp({ projectId: Deno.env.get("FIREBASE_PROJECT_ID") })
} else {
const serviceAccount = JSON.parse(Deno.env.get("FIREBASE_SERVICE_ACCOUNT") || "{}")
console.log(`initializing firebase app ${serviceAccount.project_id}`)
try {
const credential = firebase.credential.cert(serviceAccount)
//@ts-ignore types don't work correctly with deno
const firebaseConfig: firebase.AppOptions = {
projectId: serviceAccount.project_id,
credential,
databaseURL: serviceAccount.database_url,
}
firebase.initializeApp(firebaseConfig)
} catch (err: any) {
console.error(`Error initializing firebase app`, err)
}
}
return firebase
}
const verifyFirebaseEmulatorToken = async (token: string): Promise<jose.JWTPayload | undefined> => {
const firebase = await initFirebaseApp()
try {
const v = await firebase.auth().verifyIdToken(token)
return v
} catch (err: unknown) {
console.error(`Error verifying firebase emulator token`, err)
}
return undefined
} |
Thanks for the full example. The firebase import seems to work for me. I do get an error on initialization though, but that's because I do not have a valid value set for I wonder if the error occurs because of some issue with firebase module that's already cached. Can you try bumping up the version of it to the latest? which is 11.8.0 (https://www.npmjs.com/package/firebase-admin) |
@laktek I already tried clearing deno cache. Updating to latest firebase admin also does not help. In this case you can ignore the branch using FIREBASE_SERVICE_ACCOUNT, I don't actually use that anymore. The failing case is with
and running just the firebase auth emulator with |
BTW, does it work with Deno CLI? |
@laktek if I try to run it locally with those permissions Deno asks for permission to read files
Could that cause the crash on the edge runtime? Looks like the google APIs attempt to read credentials from the FS by default. |
That's the issue - Edge Functions don't have file system access when hosted. Edge Runtime also mimics this behavior locally. If this function is something you'd only need for local development but not in production, maybe best way would be to run it with |
Makes sense. Perhaps the edge runtime could offer a more useful error message in this case?
… On May 18, 2023, at 5:00 PM, Lakshan Perera ***@***.***> wrote:
That's the issue - Edge Functions don't have file system access when hosted. Edge Runtime also mimics this behavior locally. If this function is something you'd only need for local development but not in production, maybe best way would be to run it with deno run with necessary permissions.
—
Reply to this email directly, view it on GitHub <#82 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAGRWVL7JGRLRDLJOGRBZPTXG2EYVANCNFSM6AAAAAAXXUTDDU>.
You are receiving this because you were mentioned.
|
Yep, we will look into it. I'll close this ticket for now. |
Bug report
Describe the bug
I upgraded from Supabase cli v1.49.4 to 1.55.1. After doing so my edge function that imports
firebase-admin
no longer runs, it crashes withIdentifier '__f$' has already been declared
. This function worked fine on supabase cli 1.49.4 (not sure which edge-runtime version that is).To Reproduce
import firebase from "https://esm.sh/[email protected]?bundle&target=deno&no-check"
Expected behavior
Imports that previously worked should continue working
Screenshots
N/A
System information
Additional context
This worked fine with Supabase cli v1.49.4. I've deleted deno.lock and all deno cache files and the issue persists. If I switch back to cli 1.49.4 it works again but then I can't import local code since that feature was just released.
The text was updated successfully, but these errors were encountered: