score:0
cd src
from project file inside src do npm install firebase
,i was facing same issue, but this solution sorted my problem.
score:0
google has updated firebase from version 8 to modular web sdk. for this reason if you are using firebase@>9.0.0
then it will be a bit different.
in the firebase.js
file you need to import firebase like this.
import firebase from "firebase/compat/app";
so a sample of your firebase.js
will look like this
import firebase from "firebase/compat/app";
import { firebase_config } from "./constants/firebase";
import "firebase/compat/storage";
firebase.initializeapp(firebase_config);
export const storage = firebase.storage();
export default firebase;
here firebase_config
is your firebase configuration
as shown in the example use this storage
object in other files.
as here i used this storage
to other functions and worked on its functionalities like upload files etc.
i haven't tried with other services like authentication but at least firebase-storage service worked for me
score:1
the last time i had to install firebase was over 6 months ago and that was "firebase": "^8.6.2". the configuration looked something like;
import firebase from 'firebase/app';
import 'firebase/auth';
import 'firebase/firestore';
import 'firebase/storage';
import 'firebase/messaging';
import 'firebase/analytics';
import {
api_key,
auth_domain,
database_url,
project_id,
storage_bucket,
messaging_sender_id,
app_id,
measurement_id,
messaging_vapid_key,
} from '../config';
const config = {
apikey: api_key,
authdomain: auth_domain,
databaseurl: database_url,
projectid: project_id,
storagebucket: storage_bucket,
messagingsenderid: messaging_sender_id,
appid: app_id,
measurementid: measurement_id,
};
// initialize firebase app with configurations
firebase.initializeapp(config);
// setup firestore
const analytics = firebase.analytics();
const database = firebase.firestore();
const storage = firebase.storage();
// setup push messaging
let messaging = null;
if (firebase.messaging.issupported()) {
messaging = firebase.messaging();
messaging.usepublicvapidkey(messaging_vapid_key);
}
export {
firebase, storage, messaging, analytics, config, database as default,
};
as of the time of posting this, firebase is at v9 and a lot has changed. kindly refer to the official doc here
for help with setting up firebase on a project.
score:3
i found that this is the best/easiest way to use in react.js with no problem ....you can try to import like this ( "firebase": "^9.6.1",) :
import firebase from 'firebase/compat/app';
import 'firebase/compat/auth';
import 'firebase/compat/firestore';
create your configfile .....
const firebaseconfig = { your config data ...};
and then you can use it in this way without any annoying error :
const firebaseapp = firebase.initializeapp(firebaseconfig);
const db = firebaseapp.firestore();
const auth = firebase.auth();
const provider = new firebase.auth.googleauthprovider();
i hope it can help for others who have the same problem i had
score:9
first run
npm install --save firebase
and instead of this:
import * as firebase from "firebase"
use this:
import * as firebase from "firebase/app";
source: https://firebase.google.com/docs/web/setup#node.js-apps
and also this:
import firebase from 'firebase'
to this:
import firebase from '../firebase'
and remove @react-native-firebase
libraries because they won't work with expo.
Source: stackoverflow.com
Related Query
- Cannot resolve module "firebase" from 'firebase.js' : Firebase could not be found within the project
- "module not found : Error: Cannot resolve module 'react/lib/ReactMount' "
- How to fix this error : " Module not found :can't resolve popper.js "
- cannot evaluate module 'react-native-maps' : Configuration with name 'default' not found
- npm install from github: Module not found: Can't resolve 'react-big-calendar'
- Typescript Module not found Can't resolve
- Module not found Error: Can't resolve 'history' in @types/history
- Module not found: Error: Cannot resolve module 'fs'
- react-native : Unable to resolve module `tty` from ''.../node_modules/window-size/index.js": Module does not exist in the module map
- Module not found: Error: Cannot resolve module 'react-addons-test-utils'
- Module not found: Error: Cannot resolve module 'react-redux'
- Rollup error: could not load a module from @babel/runtime when importing a Material-UI component
- Module not found: Error: Cannot resolve module 'react' when I use webpack
- Module not found: Error: Cannot resolve module 'routes'
- I cannot understand " Module not found: Error: Can't resolve 'fs' '"
- How to resolve module not found error in webpack/reactjs app?
- Module not found: Error: Cannot resolve module 'components/app'. webpack + reactjs issue
- import firebase from "firebase" module not working in reactjs even the module is already installed
- Module not found: Error: Cannot resolve 'file' or 'directory'
- Could not resolve dependency error peer react@"^16.8.0 || ^17.0.0" from @material-ui/core@4.12.4
- Cannot import firebase into react.js project. "Module not found: Error: Package path . is not exported from package"
- console throws that module from existing dir is: ` Module not found: Error: Can't resolve './components/InfoPanel.js/' in`
- webpack: ERROR in Entry module not found: Error: Cannot resolve 'file' or 'directory' .jsx
- Firebase module not found even if installed
- Module not found: Error: Can't resolve './App' from React 18 w/TypeScript
- Module not found error: package path ./cjs/react.development is not exported from package
- React-Redux and Firebase : Module not found: Can't resolve '../database/config'
- Can't resolve module not found in React.js
- React - Parcel - build failed. Error: Could not resolve module "self-published/parcel-swc.darwin-x64.node"
- module not found firebase
More Query from same tag
- Use material ui svg icons as background image
- Why React router v4 makes incorrect redirect?
- Ag-grid opposite method to cellFocused
- Passing down use state values gives undefined
- Async function inside useMemo not working
- Private Component with a Private Route nested
- HTML Element with React variable does not display ASCII
- React "Cannot update a component (`BrowserRouter`) while rendering a different component" warning when registering a new user using firebase
- TypeError: Cannot read property 'local' of undefined
- Access latest state in useMemo
- Using Redux-Form for search filters, how can I "reset" and re-submit the form?
- React bootstrap form is not rendering as expected
- How do I get an absolute positioned div to sit centred horizontally with a fixed div?
- how to set value after map function runs in useEffect
- material ui pagination component text color to be grey
- How to declare a nested Javascript object in one statement with variable keys
- Handling external function imports
- React import component names clashing
- Where to put static files in webpack development
- chakra ui - the style does not apply
- Shows random number enqueuesnackbar (notistack) in react js
- Event handlers, render and other methods binding in React
- ReactFire - get 'Objects are not valid as a React child' when binding Firebase to React state
- react phone input 2 onlyCountries prop not working with array
- React > How to set focus on the input field after adding a new row by using react-table
- ES6 computed property in react
- How to pass a prop down in React fullpage wrapper
- Setting state in React useEffect hook
- touch previous props with React.useEffect()
- How to make a direct link, so it resets the whole path in React-router-dom