2

fire.js file

import firebase from 'firebase';
const firebaseConfig = {
apiKey: "AIzaSyCAXvS25TnYA3qliFTP5vNUl4hU0Ilwv2U",
authDomain: "react-firebase-auth-signup.firebaseapp.com",
projectId: "react-firebase-auth-signup",
storageBucket: "react-firebase-auth-signup.appspot.com",
messagingSenderId: "912198243014",
appId: "1:912198243014:web:bd683a011865825259fdc7"


}const fire= firebase.initialApp(firebaseConfig);
export default fire;

App.js file

import React,{Component} from 'react';
import './App.css';
import fire from './config/fire';
import Home from './Home';
import Logup from './Logup';
class App extends Component{
constructor(props){
super(props);
this.state={
  user:{}
}`}`
componentDidMount(){
this.authListener();
}authListener(){
  fire.auth().onAuthStateChanged((user)=>{
    if(user){
      this.setState({user})
    }
    else{
      this.setState({user:null})
    }
  })

}


render(){
return (
  <div className="App">
    <h1>Hello world</h1>
    {this.state.user?(<Home/>):(<Logup/>)}
    console.log(firebase.default.auth)
  </div>
);


}
}

export default App;

## Error ##  

Compiled with problems:X

ERROR in ./src/config/fire.js 3:0-32

Module not found: Error: Package path . is not exported from package D:\myprojects\firebase projects\Signin-signup-form\signin-up\node_modules\firebase (see exports field in D:\myprojects\firebase projects\Signin-signup-form\signin-up\node_modules\firebase\package.json)

4
  • You have a typo on your fire.js. Try changing firebase.initialApp to firebase.initializeApp Commented Mar 16, 2022 at 7:24
  • What are you using? Firebase v8 or v9? Commented Mar 16, 2022 at 7:31
  • firebase version : v9 Commented Mar 16, 2022 at 8:28
  • I am try this changed firebase.initialApp to firebase.initializeApp. it showing same error Commented Mar 16, 2022 at 8:30

2 Answers 2

5

Ensure to get the latest firebase module:

npm i firebase@latest

For v9, use this code as follows:

import { initializeApp } from "firebase/app";
import { getAuth, onAuthStateChanged } from "firebase/auth";

const firebaseConfig = { 
// your-config 
};

const fire = initializeApp(firebaseConfig);

export default fire;

To get the auth, use the code below:

const auth = getAuth(fire);
onAuthStateChanged(auth, user => {
  // Check for user status
});

For more information about using Firebase v9, you may check this documentation.

Sign up to request clarification or add additional context in comments.

Comments

2

npm i firebase@latest

and import firebase from 'firebase/compat/app';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.