收到错误消息:找不到模块:无法解析“ firebase / app”

时间:2020-06-25 09:12:36

标签: reactjs firebase

import 'firebase/auth';
import 'firebase/database';
import 'firebase/storage';



var firebaseConfig = {
    apiKey: "AIzaSyCEtbuZ3oIA8amHdyOBXMLLmHCZMuHIPVg",
    authDomain: "react-slack-clone-6284c.firebaseapp.com",
    databaseURL: "https://react-slack-clone-6284c.firebaseio.com",
    projectId: "react-slack-clone-6284c",
    storageBucket: "react-slack-clone-6284c.appspot.com",
    messagingSenderId: "1010926924701",
    appId: "1:1010926924701:web:d5d331af0cfe6fd31db574",
    measurementId: "G-9K7S58J5LF"
  };
  // Initialize Firebase
  firebase.initializeApp(firebaseConfig);
  firebase.analytics();

  export default firebase;

我的firebase.js文件位于src文件夹中,并且出现了如上所述的错误。在将Firebase导入Register.js的同时,我正在包容此错误

1 个答案:

答案 0 :(得分:0)

请参见https://firebase.google.com/docs/web/setup#using-module-bundlers

您应该添加import * as firebase from "firebase/app";

// Firebase App (the core Firebase SDK) is always required and must be listed first
import * as firebase from "firebase/app";

// If you enabled Analytics in your project, add the Firebase SDK for Analytics
import "firebase/analytics";

// Add the Firebase products that you want to use
import "firebase/auth";
import "firebase/firestore";

// TODO: Replace the following with your app's Firebase project configuration
const firebaseConfig = {
  // ...
};

// Initialize Firebase
firebase.initializeApp(firebaseConfig);