gpt4 book ai didi

javascript - 为浏览器代码导入 geofire-common 和 firestore

转载 作者:行者123 更新时间:2023-12-03 08:13:32 24 4
gpt4 key购买 nike

尝试在浏览器代码中使用 geofire-common 时我有点困惑。

一开始,我使用 NodeJS 进行了成功的尝试,它使用 geofire-common 引用 here in the Google documentation代码如下所示:

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

然后,我想从浏览器端完成这项工作......我偶然发现了 this example 。在这个例子中,我可以看到一个“require”函数,所以我猜它与老式的 commonJS 模块有关:

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

Require 不是标准 JavaScript API 的一部分,应该是 NodeJS 特定的(这有点奇怪,因为我认为示例是浏览器代码),所以我尝试使用 ES6 导入..

import {geofire} from 'geofire-common';

...没有成功:

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

如果周围的一些 JS 专家愿意透露一些关于这 2 个软件包的信息,并帮助我正确导入 geofire(如果可能的话),我们将不胜感激。

最佳答案

我认为你可以使用

import * as geofire from 'geofire-common';

关于javascript - 为浏览器代码导入 geofire-common 和 firestore,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70084254/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com