react-native-firebase icon indicating copy to clipboard operation
react-native-firebase copied to clipboard

firebase is not defined

Open ursvasan opened this issue 2 years ago • 3 comments

I am new to JavaScript, may be i am missing something obvious. Ideally it should have worked as it is.

I run the app and in Registration screen I get the following error. I tried googling for the issue and tried to include

  <head>
    <script src='https://cdn.firebase.com/js/client/2.2.1/firebase.js'></script>
    <script src='https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js'></script>
  </head>

I still get the error below. What am i missing ?

Uncaught ReferenceError: firebase is not defined at onRegisterPress (RegistrationScreen.js:21:1) at onPress (RegistrationScreen.js:96:1) at onClick (PressResponder.js:348:1) at HTMLUnknownElement.callCallback (react-dom.development.js:4164:1) at Object.invokeGuardedCallbackDev (react-dom.development.js:4213:1) at invokeGuardedCallback (react-dom.development.js:4277:1) at invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:4291:1) at executeDispatch (react-dom.development.js:9041:1) at processDispatchQueueItemsInOrder (react-dom.development.js:9073:1) at processDispatchQueue (react-dom.development.js:9086:1)

ursvasan avatar Mar 12 '23 02:03 ursvasan

I figured I didnt include the line

import { firebase } from '../../firebase/config'

in RegistrationScreen.js and thats the reason for the above error. Now firebase is loading but still registration screen is not working. I get the following error when i call firebase.auth() in RegistrationScreen.js > onRegisterPress

Uncaught TypeError: _firebase_config__WEBPACK_IMPORTED_MODULE_4__.firebase.auth is not a function

I have the following in ./src/firebase/config.js


var firebase = require("firebase/app");
require("firebase/auth");
require("firebase/firestore");

const firebaseConfig = {
  apiKey: 'xxxxx',
  authDomain: 'abcd.firebaseapp.com',
  databaseURL: 'https://xyz.firebaseio.com',
  projectId: 'xyz',
  storageBucket: 'xyzappspot.com',
  messagingSenderId: '12345',
  appId: '1:123456',
};

firebase.initializeApp(firebaseConfig);
console.log(firebase);
export { firebase };

ursvasan avatar Mar 12 '23 03:03 ursvasan

Turns out I am using Firebase 9.x and it has lot of breaking changes and this tutorial is based on a older version. For the latest changes refer to the article

ursvasan avatar Mar 13 '23 21:03 ursvasan

@ursvasan I know this is a bit late but if you wanted a reference for the Firebase 9 modular SDK you can find it here @ https://github.com/rybaier/react-native-firebaseModular ( I updated all the syntax and made a pull request)

I also created my own repo of it and added a few more features like SSO for Google and Apple, deleting accounts, update and delete for entities, and log out. you can find it here @ https://github.com/rybaier/react-native-firebase.

rybaier avatar May 06 '24 21:05 rybaier