Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

import geofire-common with firestore for browser code

I'm a bit confused trying to use geofire-common in browser code.

In the beginning, I've made a successful attempt with NodeJS which uses geofire-common referenced here in the Google documentation and which code looks like this:

import { createRequire } from 'module'; // <------ trick to get a require function
const require = createRequire(import.meta.url);

const { initializeApp, cert } = require('firebase-admin/app');
const { getFirestore } = require('firebase-admin/firestore');

const serviceAccount = require('./serviceAccountKey.json');

initializeApp({
  credential: cert(serviceAccount),
});

const db = getFirestore();
const geofire = require('geofire-common'); //<---------- geofire-common

Then, I wanted to make this work from the browser side... and I stumbled uponthis example. In this example, I can see a 'require' function so I guess it has something to do with old school commonJS module:

const geofire = require('geofire-common');

Require is not part of the standard JavaScript API and should be NodeJS specific (which is a bit strange because i thought the example was browser code), so I've tried to use an ES6 import..

import {geofire} from 'geofire-common';

... without success :

The requested module '/node_modules/.vite/geofire-common.js?v=738ba8db' does not provide an export named 'geofire'

If some of the JS experts around would be willing to shed some light about those 2 packages and help me to correctly import geofire if it's possible, that would be much appreciated.

like image 909
Big_Boulard Avatar asked Dec 31 '25 17:12

Big_Boulard


1 Answers

I think you can use

import * as geofire from 'geofire-common';
like image 124
salami Avatar answered Jan 02 '26 07:01

salami



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!