Having trouble with the firebase module import in ReactJS?

Encountering an Error

.

/firebase.js:2:0
Module not found: Package path . is not exported from package C:\Users\krish\Desktop\FACEBOOK _CLONE\facebook_clone\node_modules\firebase (see exports field in C:\Users\krish\Desktop\FACEBOOK _CLONE\facebook_clone\node_modules\firebase\package.json)
Did you mean './firebase'?
Requests that should resolve in the current directory need to start with './'.
Requests that start with a name are treated as module requests and resolve within module directories (node_modules).
If changing the source code is not an option there is also a resolve options called 'preferRelative' which tries to resolve these kind of requests in the current directory too.
  1 | 
> 2 | import firebase from 'firebase'
  3 | import 'firebase/firestore'
  4 | 
  5 | 

Import trace for requested module:
./Components\InputBox.js
./Components\Feed.js
./pages\index.js

https://nextjs.org/docs/messages/module-not-found

Firebase Configuration Code

import firebase from 'firebase'
import 'firebase/firestore'


// For Firebase JS SDK v7.20.0 and later, measurementId is optional
const firebaseConfig = {
    apiKey: "fasdfsadfdsafjsafsafsfsfsfsfs",
    authDomain: "facebook-clone-13234.firebaseapp.com",
    projectId: "facebook-clone-13234",
    storageBucket: "facebook-clone-13234.appspot.com",
    messagingSenderId: "76247424324242",
    appId: "1:762470571881:web:20a2432424324424324424",
    measurementId: "G-9RDT591EEG",
};

const app = !firebase.apps.length
    ? firebase.initializeApp(firebaseConfig)
    : firebase.app();

const db = app.firestore();
const storage = firebase.storage();

export  {db,storage};

About Package Installation

{
  "name": "facebook_clone",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "@heroicons/react": "^1.0.4",
    "firebase": "^9.0.0",
    "firebase-tools": "^9.16.6",
    "next": "11.1.0",
    "next-auth": "^3.29.0",
    "react": "17.0.2",
    "react-dom": "17.0.2"
  },
  "devDependencies": {
    "autoprefixer": "^10.3.3",
    "eslint": "7.32.0",
    "eslint-config-next": "11.1.0",
    "postcss": "^8.3.6",
    "tailwindcss": "^2.2.8"
  }
}

Working on a Facebook clone project utilizing ReactJS, NextJS, and Tailwind CSS. In order to incorporate images, Firebase was integrated using npm install firebase. However, upon importing Firebase from "firebase," an error is displayed.

Answer №1

Consider using this code snippet:

import * as firebase from "firebase/app";

Instead of the following:

import firebase from 'firebase'

Answer №2

Import it like so

import * as firebase from "firebase/app";

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

Exploring the seamless integration of the Material UI Link component alongside the Next.JS Link Component

Currently, I am integrating Material-UI with Next.js and would like to leverage the Material-UI Link component for its variant and other Material UI related API props. However, I also require the functionality of the Next.js Link component for navigating b ...

Ways to resolve the issue "How to address the React hook error stating "React Hook 'React.useState' is being called conditionally"?"

I encountered an issue while attempting to build my next.js project. How can I resolve it? It seems that the error is related to using hooks conditionally. ./src/lib/session.js 6:29 Error: React Hook "React.useState" is called conditionally. R ...

"Enormous NextJS logo greets users upon the initial page load following the project

I'm having some issues with the icons and styles in my NextJs project. I am using material-ui, and during development everything looks fine, but once I build the project, the icons initially appear large before resizing to normal. I have tried using d ...

The switchMap function is sending back a single item

I'm having an issue with switching the observable using the switchMap operator: return this.db.list(`UserPlaces/${this.authData.auth.auth.currentUser.uid}`, { query: { orderByChild: 'deleted', equalTo: false } }) .ma ...

Dealing with soon-to-expire access tokens from a partner API

Just starting out with Next.js and facing a common challenge without knowing where to begin. Here's the scenario: I am working with a partner who has an API that requires Bearer authentication. The Bearer token is obtained by calling an endpoint (/au ...

How can the hreflang tag be used correctly in a React application that supports multiple languages?

I have a React application with 3 pages(routes) and I support 2 languages (English and Spanish). Should I insert the following code into the <head></head> section of the public\index.html file like this? <link rel="alternate" ...

Installing Npm packages offline within a Docker container

I'm currently facing an issue while attempting to set up node-red-contrib-influxdb in a node-red docker container on a computer without internet access. My setup involves a Windows machine where I've installed node.js, along with the node-red-con ...

I am having difficulty accessing the dataset on my flashcard while working with React/Next JS

I'm currently developing a Flashcard app that focuses on English and Japanese vocabulary, including a simple matching game. My goal is to link the two cards using a dataset value in order to determine if they match or not. When I click on a flashcar ...

Exploring the Power of Apollo Queries in React Native

After reading through this blog post on integrating query components with Apollo (), I learned how to pass a function from a child component to its parent so that it can be called with the correct parameters. Despite following the instructions, I keep enc ...

Ways to encourage children to adopt a specific trait

Let's discuss a scenario where I have a React functional component like this: const Test = (props: { children: React.ReactElement<{ slot: "content" }> }) => { return <></> } When a child is passed without a sl ...

Steps to creating a custom text editor using React for generating blog content and storing it in a MongoDB database

I have a challenge of building a rich text editor for my web app, specifically for creating blog posts that will be saved in the database for user viewing. Initially, I planned to use a form with input fields where the title and content of the blog post w ...

Exporting a named export for every HTTP method is the way to go with NextJs

I'm currently working on a project to create an Airbnb clone using NextJs. The tutorial I'm following is using an experimental version, while I've opted for the latest version of NextJs. One aspect that's been causing confusion for me i ...

Difficulty encountered when saving cookies on the browser in the context of NEXTjs and Redux RTK query

Currently, I am immersed in a Django project for the backend. The XCRF token is being retrieved via API cookies, as depicted in the screenshot from Postman provided below. https://i.stack.imgur.com/zc68R.png Furthermore, access is granted through the red ...

Encountered a difficulty in resolving the dependency flawlessly within the Next.js application

Every time I try to deploy my next.js project, I encounter the same error message: npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree npm ERR! npm ERR! While resolving: <a href="/cdn-cgi/l/email-protection" class="__cf_email__" ...

Encountering the "TypeError: Cannot call a class as a function" error while using EditorJS in NextJs

I am facing an issue with integrating EditorJs into my NextJs app. This is what I have tried: Editor.js import dynamic from "next/dynamic"; let CustomEditor = dynamic(() => import("./CustomEditor"), { ssr: false ...

Tips for increasing the size of the SVG icon within Material UI iconButtons

Have you experimented with creating webpages using react.js along with the Material UI library? How can I adjust the size of an SVG icon? Recently, I developed a "create new" component, which consists of a material paper element with an add button on top. ...

Different ways to implement individual style modifications on a React mapped component

Having an issue with changing the style of a mapped TouchableOpacity. What I'm trying to achieve is that when one TouchableOpacity is clicked, its background color changes to black while also resetting the background color of any previously clicked To ...

Exploring and navigating a div containing image tags with dynamic data visualization capabilities in d3

I'm using d3 to implement zoom and pan functionality for a div element that contains multiple img tags. Although I have a rough idea of how it works, I need more clarity on the mathematical calculations and library functions required to recalculate co ...

Is it possible to identify in Next.js whether scrollRestoration was triggered, or if the back button was pressed?

I've been utilizing the scrollRestoration functionality within Next.js to save and restore the page position whenever a user navigates using the back button. However, I've encountered an issue with it not restoring the horizontal scroll position ...

Subcomponent in React is not rendering as expected

I have a primary React component with a subcomponent named AttributeInput. To prevent redundancy in my code, I moved some of the logic from the main component to a method within AttributeInput. My attempt at referencing this code looks like this: {this.s ...