Reputation: 178
When I import firebase on react-native then faces some issues like this.
import * as firebase from "firebase";
var firebaseConfig = {
apiKey: "[data_private]",
authDomain: "[data_private]",
databaseURL: "https://[data_private].firebaseio.com",
projectId: "[data_private]",
storageBucket: "[data_private]",
messagingSenderId: "[data_private]",
appId: "[data_private]"
};
firebase.initializeApp(firebaseConfig);
Upvotes: 1
Views: 3562
Reputation: 1
Instead of:
firebase.initializeApp(firebaseConfig);
Use as:
const app = firebase.initializeApp(firebaseConfig);
Upvotes: 0
Reputation: 392
For me, this solution is working
Step 1: Install firebase using npm:
npm install --save firebase
Step 2: Add this line of code in your react native code:
var firebase = require('firebase');
var firebaseConfig = {
apiKey: "[private_data]",
authDomain: "[private_data]",
projectId: "[private_data]",
storageBucket: "[private_data]",
messagingSenderId: "[private_data]",
appId: "[private_data]",
measurementId: "[private_data]"
};
const fireApp = firebase.initializeApp(firebaseConfig);
console.log(fireApp);
Upvotes: 1
Reputation: 2242
You are using firebase
package which is for web. You must use native packages like react-native-firebase
Upvotes: 1
Reputation:
You need to add the latest version of the firebase.
You can useyarn add @react-native-firebase/app
or npm i @react-native-firebase/app
.
And then import firebase from it.
For reference, you can use react-native-firebase
Upvotes: 2
Reputation: 80914
According to the docs:
First you need to install firebase
package:
npm install --save firebase
Then import it using firebase/app
:
// Firebase App (the core Firebase SDK) is always required and
// must be listed before other Firebase SDKs
import * as firebase from "firebase/app";
Upvotes: 2