简体   繁体   English

尝试导入错误:“firebase/app”不包含默认导出(导入为“firebase”)

[英]Attempted import error: 'firebase/app' does not contain a default export (imported as 'firebase')

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')" .我尝试使用 React 使用 firabase 身份验证,但它显示错误, "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 * as firebase from "firebase/app"然后休息显示错误的代码。

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;

Firebase modular SDK ( v9 ) is officially released and npm install firebase now installs this instead of the older namespaced version ( v8 ). Firebase 模块化 SDK ( v9 ) 正式发布, npm install firebase现在安装它,而不是旧的namespaced版本 ( v8 )。 If you are using v9 then refactor your code to this:如果您使用的是v9 ,则将您的代码重构为:

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 recommend following the documentation and continue using the new modular SDK.我建议遵循文档并继续使用新的模块化 SDK。 If you have an existing and want to use the existing namespaced version, then you can replace your imports with compat libraries as follows:如果你有一个现有的并想使用现有的命名空间版本,那么你可以用兼容库替换你的导入,如下所示:

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

firebase.initializeApp({...config})

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

Checkout this video from Firebase for getting started with v9.观看来自 Firebase 的此视频,了解 v9 入门。

use this export method使用此导出方法

import {firebase} from 'firebase/app';

instead of代替

import firebase from 'firebase/app';

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 firebase 存储:在“firebase/app”中找不到导出“存储”(导入为“firebase”) - firebase storage: export 'storage' (imported as 'firebase') was not found in 'firebase/app' firebase 存储:在“firebase/app”中找不到导出“存储”(导入为“firebase”)继续 - firebase storage: export 'storage' (imported as 'firebase') was not found in 'firebase/app' Continuation 未找到模块:错误:您尝试导入项目 src/ 目录之外的 /firebase/app - Module not found: Error: You attempted to import /firebase/app which falls outside of the project src/ directory 没有 Firebase 应用程序“[默认]”错误,但 firebase 已经初始化 - No Firebase App '[Default]' error but firebase is already initialized Firebase 用户导入/导出 - Firebase user import / export 类型错误:_firebase_app__WEBPACK_IMPORTED_MODULE_1___default.a.auth 不是函数 - TypeError: _firebase_app__WEBPACK_IMPORTED_MODULE_1___default.a.auth is not a function Google Cloud Functions Firebase 错误 默认的 Firebase 应用已经存在 - Google Cloud Functions Firebase Error The default Firebase app already exists 从 Angular Ionic 项目中的“@firebase/app”导入 { Firebase } 时出错 - Error with import { Firebase } from '@firebase/app' in Angular Ionic project React/Firebase 错误“未捕获(承诺中)TypeError:(0,_firebase__WEBPACK_IMPORTED_MODULE_1__.default)不是函数” - React/Firebase error "Uncaught (in promise) TypeError: (0 , _firebase__WEBPACK_IMPORTED_MODULE_1__.default) is not a function" React Native 错误:没有创建 Firebase App '[DEFAULT]' - 调用 firebase.initializeApp() - React Native Error: No Firebase App '[DEFAULT]' has been created - call firebase.initializeApp()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM