我正在尝试在网络工作者中使用 h3-js。我得到的错误是:
Uncaught ReferenceError: document is not defined
at libh3-browser.js:6
at Module../node_modules/h3-js/dist/browser/h3-js.es.js (libh3-browser.js:2)
at __webpack_require__ (bootstrap:19)
at Module../src/utils/worker/methods/clusterPins.ts (clusterPins.ts:1)
at __webpack_require__ (bootstrap:19)
at Module../src/utils/worker/methods/aggregateAndClusterPins.ts (aggregateAndClusterPins.ts:1)
at __webpack_require__ (bootstrap:19)
at Module../src/utils/worker/methods/index.ts (index.ts:1)
at __webpack_require__ (bootstrap:19)
at Module../node_modules/babel-loader/lib/index.js?!./node_modules/eslint-loader/dist/cjs.js?!./src/utils/worker/index.ts (index.ts:1)
我能找到的唯一问题是在 h3-js github 上与 React-native 问题相关,这与我的无关。
代码如下所示:
import h3 from 'h3-js';
const h3Index = h3.geoToH3(37.3615593, -122.0553238, 7);
有趣的是,我能够在有任何问题的节点实例中运行它,这让我不确定是否有我遗漏的东西。