-
Notifications
You must be signed in to change notification settings - Fork 990
Description
[REQUIRED] Describe your environment
- Operating System version: MacOS Big Sur(11.5.1)
- Browser version: Chrome 92.0.4515.131
- Firebase SDK version: Firebase 9.0.0-beta 6/Firebase 9.0.0-beta 7/Firebase 9.0.0-beta 8
- Firebase Product: Auth
[REQUIRED] Describe the problem
I am consistently getting the INTERNAL ASSERTION FAILED: Expected a class definition error and the app crashes while starting up. My app is simple and i really don't do anything else much (like calling APIs in the background etc).
I am using Firebase in a NextJS app and the SDKs are the beta versions(without compat). I have the emulators setup so development is local.
As far as i recall it was working fine in earlier beta versions though i cannot exactly remember the versions since it was a few weeks ago (in a POC app, maybe beta-4 or beta-5 perhaps)
Steps to reproduce:
Note: I am not sure if this can be reproduced in a clean install. I did not attempt it since the tested versions are explicitly beta and probably could be because of some known issues.
- Install the beta versions mentioned in the issue
- Setup emulators and initialise Firebase auth
- Have a
onAuthStateChangedearly in the page loading process - attempt to load the page
The app crashed and i get the following error in the terminal:
WARNING: You are using the Auth Emulator, which is intended for local testing only. Do not use with production credentials.
[2021-08-15T09:11:11.680Z] @firebase/auth-exp: Auth (9.0.0-beta.6): INTERNAL ASSERTION FAILED: Expected a class definition
/Users/arunmenon/Sites/pwa/next/intl/sivadas/node_modules/@firebase/auth/dist/node/enum_maps-3878f8c6.js:295
throw new Error(message);
^
Error: INTERNAL ASSERTION FAILED: Expected a class definition
at debugFail (/Users/arunmenon/Sites/pwa/next/intl/sivadas/node_modules/@firebase/auth/dist/node/enum_maps-3878f8c6.js:295:11)
at debugAssert (/Users/arunmenon/Sites/pwa/next/intl/sivadas/node_modules/@firebase/auth/dist/node/enum_maps-3878f8c6.js:306:9)
at _getInstance (/Users/arunmenon/Sites/pwa/next/intl/sivadas/node_modules/@firebase/auth/dist/node/enum_maps-3878f8c6.js:328:5)
at AuthImpl.<anonymous> (/Users/arunmenon/Sites/pwa/next/intl/sivadas/node_modules/@firebase/auth/dist/node/enum_maps-3878f8c6.js:2517:90)
at step (/Users/arunmenon/Sites/pwa/next/intl/sivadas/node_modules/tslib/tslib.js:143:27)
at Object.next (/Users/arunmenon/Sites/pwa/next/intl/sivadas/node_modules/tslib/tslib.js:124:57)
at /Users/arunmenon/Sites/pwa/next/intl/sivadas/node_modules/tslib/tslib.js:117:75
at new Promise (<anonymous>)
at Object.__awaiter (/Users/arunmenon/Sites/pwa/next/intl/sivadas/node_modules/tslib/tslib.js:113:16)
at /Users/arunmenon/Sites/pwa/next/intl/sivadas/node_modules/@firebase/auth/dist/node/enum_maps-3878f8c6.js:2514:54
Relevant Code:
How i initilaize:
import firebaseClientApp,{ initializeApp,FirebaseApp, getApp } from 'firebase/app';
// import { initializePerformance } from 'firebase/performance';
import { getFirestore, /* connectFirestoreEmulator, */ useFirestoreEmulator, FirebaseFirestore,} from 'firebase/firestore';
import { browserLocalPersistence, getAuth, setPersistence, /* connectAuthEmulator, */ useAuthEmulator, Auth,indexedDBLocalPersistence} from 'firebase/auth';
import {getStorage, StorageService, /* connectStorageEmulator */ useStorageEmulator} from 'firebase/storage';
import { getAnalytics,Analytics } from "firebase/analytics";
const CLIENT_CONFIG = {
apiKey: process.env.NEXT_PUBLIC_FIREBASE_API_KEY,
authDomain: process.env.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN,
databaseURL: process.env.NEXT_PUBLIC_FIREBASE_DATABASE_URL,
projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID,
storageBucket: process.env.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET,
messagingSenderId: process.env.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID,
appId: process.env.NEXT_PUBLIC_FIREBASE_APP_ID,
measurementId: process.env.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID
};
let firebaseApp: FirebaseApp;
let firestoreClient:FirebaseFirestore,authClient:Auth,storageClient:StorageService, analyticsClient: Analytics;
(() => {
try {
firebaseApp = getApp();
try {
analyticsClient = getAnalytics();
} catch (error) {
console.log(error)
}
} catch (error) {
firebaseApp = initializeApp(CLIENT_CONFIG);
//I kept getting the window not defined error so had to use this:
if(typeof window !== "undefined"){
analyticsClient = getAnalytics();
}
firestoreClient=getFirestore();
// connectFirestoreEmulator(firestoreClient, 'localhost', 8080);
useFirestoreEmulator(firestoreClient, 'localhost', 8080);
try {
authClient=getAuth();
setPersistence(authClient, browserLocalPersistence);
// connectAuthEmulator(authClient, "http://localhost:9099");
useAuthEmulator(authClient, "http://localhost:9099");
} catch (error) {
console.error(error)
}
storageClient = getStorage();
useStorageEmulator(storageClient, "localhost", 9199);
// connectStorageEmulator(storageClient,"localhost",9199);
}
})()
export {
firebaseApp,
firestoreClient,
authClient,
storageClient,
analyticsClient
}
The initiation happens early in a React useEffect:
useEffect(() => {
let unsub: Unsubscribe;
const unsubscribe = onAuthStateChanged(authClient, (user) => {
if(user){
const {email, displayName, photoURL, providerId, providerData, uid, metadata, emailVerified} = user;
logEvent(analyticsClient, 'login');
//...more code, basically some firestore calls
},(err=>{
console.error("ERROR IN users snapshot", err)
}));
}
else {
dispatch({"kinds": Kinds.SetUserState, "payload": null})
}
});
return () => {
unsubscribe();
if(unsub){
unsub();
}
};
}, []);