Home > Net >  Svelte Firebase: Unresolved function or method firestore()
Svelte Firebase: Unresolved function or method firestore()

Time:11-04

I'm working with svelte on a todo list with firebase. I think I have everything installed, but I get the error in my firebase.js file: Unresolved function or method firestore() same for auth(). what is the reason for this? My Code:

import firebase from "firebase/app";
import "firebase/auth";
import "firebase/firestore";

var firebaseConfig = {
// my config here

};

firebase.initializeApp(firebaseConfig);

export const auth = firebase.auth();
export const googleProvider = new firebase.auth.GoogleAuthProvider();

export const db = firebase.firestore();

Thanks for any help.

CodePudding user response:

If you use the latest and recommended firebase version (9) your firebase.js looks like this:

import { initializeApp } from 'firebase/app';
import { getAuth, GoogleAuthProvider } from "firebase/auth";
import { getFirestore } from "firebase/firestore";
import { getStorage } from "firebase/storage";
import { firebaseConfig } from "../firebase.config.js";

const app = initializeApp(firebaseConfig);

export const auth = getAuth();
export const provider = new GoogleAuthProvider(); 
export const db = getFirestore(app);
export const storage = getStorage(app);

and you have to include firebase in your package.json like:

{
  "name": "...",
  "version": "1.0.0",
  "author": "...",
  "repository": {
    "type": "git",
    "url": "https://github.com/..."
  },
  "license": "MIT",
  "type": "module",
  "scripts": {
    "dev": "vite",
    "build": "vite build",
    "serve": "vite preview"
  },
  "devDependencies": {
    "@sveltejs/vite-plugin-svelte": "^1.0.0-next.30",
    "svelte": "^3.44.0",
    "vite": "^2.6.12",
    "firebase": "^9.1.3",
  }
}

This works fine for me.

  • Related