我正在尝试在网络工作者中使用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)
我能够找到的唯一问题是在与React-native问题有关的h3-js github上,与我的问题无关。
代码看起来像这样:
import h3 from 'h3-js';
const h3Index = h3.geoToH3(37.3615593, -122.0553238, 7);
有趣的是,我能够在有任何问题的节点实例中运行它,这使我不确定是否缺少某些东西。
这是当前Emscripten构建的局限性-我们实际上不需要document
,但是Emscripten运行时代码中对它的引用很深。希望我们将来能够删除它。同时,将document = {}
填充到global
或this
上应提供一种解决方法。