【发布时间】:2020-07-14 04:23:42
【问题描述】:
我正在尝试在网络工作者中使用 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);
有趣的是,我可以在有任何问题的节点实例中运行它,这让我不确定我是否缺少某些东西。
【问题讨论】:
-
我没有时间给出完整的答案,您可能想遵循与this answer of mine 中的方法类似的方法,但为 h3js 做吧。
标签: web-worker h3