javascript - Attempted import error: 'firebaseapp' does not contain a default export (imported as 'fireb

I tried to work with firabase authentication using React but it says the error, "Attempted import

I tried to work with firabase authentication using React but it says the error, "Attempted import error: 'firebase/app' does not contain a default export (imported as 'firebase')". If I use import * as firebase from "firebase/app" then rest off the code showing errors.

import firebase from 'firebase/app';
import 'firebase/auth';
    
const app = firebase.initializeApp({
  apiKey: process.env.REACT_APP_FIREBASE_API_KEY,
  authDomain: process.env.REACT_APP_FIREBASE_AUTH_DOMAIN,
  projectId: process.env.REACT_APP_FIREBASE_PROJECT_ID,
  storageBucket: process.env.REACT_APP_FIREBASE_STORAGE_BUCKET,
  messagingSenderId: process.env.REACT_APP_FIREBASE_MESSAGING_SENDER_ID,
  appId: process.env.REACT_APP_FIREBASE_APP_ID
});
    
export const auth = app.auth();

export default app;

I tried to work with firabase authentication using React but it says the error, "Attempted import error: 'firebase/app' does not contain a default export (imported as 'firebase')". If I use import * as firebase from "firebase/app" then rest off the code showing errors.

import firebase from 'firebase/app';
import 'firebase/auth';
    
const app = firebase.initializeApp({
  apiKey: process.env.REACT_APP_FIREBASE_API_KEY,
  authDomain: process.env.REACT_APP_FIREBASE_AUTH_DOMAIN,
  projectId: process.env.REACT_APP_FIREBASE_PROJECT_ID,
  storageBucket: process.env.REACT_APP_FIREBASE_STORAGE_BUCKET,
  messagingSenderId: process.env.REACT_APP_FIREBASE_MESSAGING_SENDER_ID,
  appId: process.env.REACT_APP_FIREBASE_APP_ID
});
    
export const auth = app.auth();

export default app;
Share edited Aug 27, 2021 at 5:47 Dharmaraj 51k8 gold badges66 silver badges97 bronze badges asked Aug 26, 2021 at 18:04 Maruf HasnatMaruf Hasnat 972 silver badges4 bronze badges 1
  • Please include more information about how you are integrating Firebase into your app, including the versions of any SDKs you've added to your package.json. We should have enough information in the question to duplicate the error as you see it. – Doug Stevenson Commented Aug 26, 2021 at 18:19
Add a ment  | 

2 Answers 2

Reset to default 7

Firebase modular SDK (v9) is officially released and npm install firebase now installs this instead of the older namespaced version (v8). If you are using v9 then refactor your code to this:

import { initializeApp } from 'firebase/app';
import { getAuth } from 'firebase/auth';
import { getDatabase } from "firebase/database";

const app = initializeApp({...config});

export const auth = getAuth()
const database = getDatabase();

export { auth, database }

I'd remend following the documentation and continue using the new modular SDK. If you have an existing and want to use the existing namespaced version, then you can replace your imports with pat libraries as follows:

import firebase from 'firebase/pat/app';
import 'firebase/pat/auth';

firebase.initializeApp({...config})

const auth = firebase.auth()
const database = firebase.database()

Checkout this video from Firebase for getting started with v9.

use this import method

import { firebase } from 'firebase/app';

instead of

import firebase from 'firebase/app';

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742402368a4437167.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信