After upgrading to version 8 of the Firebase JS SDK, the "firestore" module (imported as "firebase") could not be located within the "firebase" package

After upgrading the firebase JS SDK from v7 to v8.0.0, I changed my import of firebase as shown below.

import * as firebase from 'firebase';

However, attempting to access certain properties resulted in an error message:

firebase.firestore.FieldValue.serverTimestamp()
firebase.User
firebase.auth.UserCredential

The error: export 'firestore' (imported as 'firebase') was not found in 'firebase' Property 'firestore' does not exist on type 'typeof import("appPath/node_modules/firebase/index")'

To work around this issue, I had to modify my code by using firebase.default instead, like so:

firebase.default.firestore.FieldValue.serverTimestamp()

Is this the correct solution to resolve the problem?

In addition to that, AngularFire is also being used in this project. I attempted another approach:

import firebase from 'firebase/app';
import 'firebase/firestore';
export const firestore = firebase.firestore();

Unfortunately, this led to a different error:

Uncaught FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app).

Answer №1

If you're encountering a similar error with Firebase version 9, make sure to update your path to:

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

Instead of using:

import firebase from 'firebase/app';
import 'firebase/auth';
import 'firebase/firestore';
...

This tip was sourced from the official Firebase documentation.

Answer №2

Encountered a similar issue after updating to Angular 11, I attempted a fix by installing the firebase-admin library as suggested in this thread. However, this solution isn't designed for browser use and caused additional complications, leading me to abandon it.

Upon reviewing the release notes of AngularFire, it became clear that the latest version no longer supports older versions of the JS SDK, prompting me to delete node_modules, package-lock.json, and execute npm cache clean --force followed by npm install to start afresh. Though this did not resolve the issue entirely, it provided a sense of achievement.

Finding guidance in this thread, I made a crucial change in the library import statement:

From: 'import * as firebase from 'firebase/app';

To:

import firebase from 'firebase/app';

This adjustment successfully eliminated the "cannot find firestore" error, allowing the code to compile correctly. The original function remains functional:

get firebaseTimestamp() { return firebase.firestore.FieldValue.serverTimestamp(); }

I trust this information proves valuable in resolving your own sticky bug.

Answer №3

It is recommended to utilize the following code snippet:

import firebase from "firebase/app";
import "firebase/database";

in place of

'import * as firebase from 'firebase/app';

This adjustment could potentially be beneficial.

Answer №4

Prior to: update 8

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

SWITCH TO ====>

After the upgrade: version 9 streamlined

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

Answer №5

Greetings! Below is the code snippet that I am currently utilizing:

import { AngularFireAuth } from '@angular/fire/compat/auth';


import firebase from 'firebase/compat/app';

I trust this will be beneficial!

Answer №6

To simplify, just follow these steps:

import 'firebase/compat/database'; // when using angular-fire-database.js

import firebase from 'firebase/compat/app'; // when working with angular-fire.js

Answer №7

Encountered issues during compilation: Attempted to export 'default' (renamed as 'firebase') from 'firebase/app'

import firebase from 'firebase/app';
{ auth } from '../misc/firebase';

Despite updating to v9, modifying the import statement did not resolve the error

import firebase from 'firebase/compat/app';

Answer №8

The problem with your config.js file can be traced back to the way you're setting up the Firebase storage and Firestore instances.

In the latest Firebase version 9 (also known as Modular SDK), there have been changes in how Firebase is initialized and its services are accessed. It's important to now utilize the modular Firebase SDK syntax instead of the older namespace import method used in Firebase version 8 and below.

To rectify the issue in your config.js file, here is an example of how you should implement the Firebase Modular SDK syntax:

import { initializeApp } from "firebase/app";
import { getStorage } from "firebase/storage";

Answer №9

If you're using React and Firebase JS SDK v7.20.0 or later, and need to upload media files like images, follow these steps:

  1. Create a new directory in your project at src/firebase/firebaseConfig.js
/** src/firebase/firebaseConfig.js */

// FIREBASE: SDK

// Import the necessary functions from Firebase SDK
import { initializeApp } from "firebase/app";
import { getAnalytics } from "firebase/analytics";

// Configure your Firebase app with your own credentials
const firebaseConfig = {
  apiKey: "",
  authDomain: "",
  projectId: "",
  storageBucket: "",
  messagingSenderId: "",
  appId: "",
  measurementId: "",
};

// Initialize Firebase
const firebaseapp= initializeApp(firebaseConfig);

// Export the initialized Firebase app
export { firebaseapp };

  1. In your script for uploading images, add the following:
/** imageUpload.js */
// Import the firebase configuration from: src/firebase/firebaseConfig.js
import firebaseapp from "/firebase/firebaseConfig";
import { getStorage, ref } from "firebase/storage";

// Initialize the Firebase app
const storage = getStorage(firebaseapp);

// Get a Storage Reference and Upload Files: 'file' represents the image file
const storageRef = ref(storage, `images/` + file.name);
const uploadTask = uploadBytesResumable(storageRef, file);

// Check your Firebase console for the uploaded files

Refer to the official documentation for more details: Firebase Storage Web

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Set the style of the mat-select element

I'm having an issue with my select option in Angular Material. The options look fine, but when I select one, the strong tag disappears. Can anyone help me style only that part? Thank you in advance. <mat-select formControlName="projectId" ...

Tips for incorporating child components when creating unit tests in Angular 2

While working on my component, I encountered an issue with the child component during unit testing. An error message is appearing stating that the child component is not defined. Any advice or solutions would be greatly appreciated. Thank you in advance. ...

Enable the Angular button only when the radio button has been selected

Just starting out with Angular and I have a query. This is a scenario for my project at work. https://i.stack.imgur.com/R3SxA.png In this screenshot, I want to enable the "ajouter" button when at least one radio button is selected in the secure chest (s ...

Obtaining Prisma arguments by providing the table name as a string

Is there a way to retrieve the query arguments for a Prisma function by only passing the table name? Currently, I know I can obtain the table by providing the table name as a string in the following manner: function (tablename: string) { await prisma.[tab ...

Exploring ways to expand the theme.mixins feature in MUI 5

Currently, I am in the process of updating Material UI from version 4 to 5 and encountering challenges with my existing theming. Since we are using typescript, it is important to include the appropriate types when extending themes. I intend to include th ...

Guide on altering an element's attribute in Angular 2

Is there a way in Angular to dynamically change the attribute of an HTML element? I want to create a button that can toggle the type attribute of an input from password to text. Initially, I thought about implementing it like this: Template: <input na ...

Experience the dynamic synergy of React and typescript combined, harnessing

I am currently utilizing ReactJS with TypeScript. I have been attempting to incorporate a CDN script inside one of my components. Both index.html and .tsx component // .tsx file const handleScript = () => { // There seems to be an issue as the pr ...

Implementing NestJS: Integrating TypeORM Datasource without relying on class dependency injection

I have a unique situation that requires some help. Our team is in the process of integrating nestjs into our current express codebase. Previously, we were using Typeorm 0.2 and recently upgraded to 0.3. Due to the fact that we utilize functions instead of ...

Exploring the generalization of class member initialization in TypeScript

I am looking to make some modifications to the Blog constructor provided in the "Minimal working example" linked below. The objective is to refactor it using pseudo-code by leveraging a generic ModelHelper class to initialize the members of the "Blog" clas ...

Having issues with Bootstrap customization in an Angular 7 project

I am currently working on customizing a Bootstrap 4 theme within an Angular 7 project. After installing Bootstrap, I updated my angular .json file to include the following: "styles": [ "./node_modules/@angular/material/prebuilt-themes/de ...

Having trouble adding custom props to MUI-Material ListItemButtonProps? Facing a TypeScript error?

This particular task should be relatively straightforward. I am seeking a custom component that inherits all props from ListItemButtonProps, while also adding an extra state prop: type SidebarListItemButtonProps = ListItemButtonProps & { state: Sideb ...

Flow - secure actions to ensure type safety

Currently implementing flow and looking to enhance the type safety of my reducers. I stumbled upon a helpful comment proposing a solution that seems compatible with my existing codebase: https://github.com/reduxjs/redux/issues/992#issuecomment-191152574 I ...

Creating getter and setter functions for an input field model property in Angular

I need help creating getter and setter methods for an input field property. Here is my attempted code: import { Component } from '@angular/core'; @Component({ selector: 'my-app', templateUrl: './app.component.html', st ...

Is there a way to adjust this angular2 service to make it slightly more synchronous?

My goal is to create an Angular2 service that performs the following tasks: FTP to a remote server Read certain lines from a file Create a 'results' JSON object and return it to the component that called the service I have successfully impleme ...

How to handle an empty data response in Angular 2's HTTP service

My ASP.NET web API has a simple method with the following test results: $ curl localhost:5000/Api/GetAllQuestions [{"questionId":0,"value":"qqq","answers":[{"answerId":25,"value":"qwerty"}]}] However, I am encountering an issue in my Angular 2 HTTP serv ...

Can we access global variables directly in an Angular 2 HTML template?

After setting the app.settings as shown below public static get DateFormat(): string { return 'MM/DD/YYYY';} I need to utilize it in one of my HTML templates for a component. This is what I want to achieve. <input [(ngModel)]="Holiday" [dat ...

What could be the reason for TypeScript inferring the generic type as an empty string?

I have developed a React component known as StateWithValidation. import { useStateWithValidation } from "./useStateWithValidation"; export const StateWithValidation = () => { const [username, setUserName, isValid] = useStateWithValidation( ( ...

Steps to modify the CSS of a custom component in Angular 8

I have been attempting to override the css of a custom component selector, however, my attempts have been unsuccessful. I have tried using ":ng-deep" but it hasn't worked. How can I go about finding a solution for this issue? app.component.html: < ...

The component is failing to store its value within the database

I'm encountering an problem when attempting to save an option in the database. To address this issue, I created a component in Svelte called StatePicker that is responsible for saving US States. However, when I try to save it in the database using a ...

Check to see if the upcoming birthday falls within the next week

I'm trying to decide whether or not to display a tag for an upcoming birthday using this boolean logic, but I'm a bit confused. const birthDayDate = new Date('1997-09-20'); const now = new Date(); const today = new Date(now.getFullYear( ...