h3-js: React-native won't compile because of the use of h3-js
importing h3-js this way import * as h3 from "h3-js";
would trigger the error below:
[Sat May 08 2021 16:50:27.116] ERROR Error: Requiring module "node_modules/h3-js/dist/browser/h3-js.js", which threw an exception: ReferenceError: Can't find variable: document
[Sat May 08 2021 16:50:27.132] ERROR ReferenceError: Can't find variable: document
I am wondering if this could be easily fixed? I am reading that there is a node version of h3-js, how can I import it instead of the browser version?
I tried to only import the function I was using at the time but I am still getting the same error
import {geoToH3} from 'h3-js';
I think the error is pointing to this code here in h3-js
var readAsync;
{
if (document.currentScript) {
scriptDirectory = document.currentScript.src;
}
if (scriptDirectory.indexOf("blob:") !== 0) {
scriptDirectory = scriptDirectory.substr(0, scriptDirectory.lastIndexOf("/") + 1);
} else {
scriptDirectory = "";
}
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 17 (1 by maintainers)
This issue should be resolved with the most recent 4.1.0 release. I have been able to use the 4.1.0 dist directly in WebWorkers now greatly speeding up computations 😃
With Deno’s recent support for npm packages, you may now use a regular import like
Easy enough, but non-standard and won’t help people on other runtimes (and not even Deno Deploy as the feature is experimental). It would be great if h3-js could simply get rid of the
document
-reference.I’m trying to use h3-js in a web-worker and I have the same problem. It would be great if a new h3-js release was published with the latest emscripten version
It looks like the bug on the Emscripten side (https://github.com/emscripten-core/emscripten/issues/14198) was fixed as of November of last year. Would it be possible to cut a new h3-js release with the latest emscripten, which hopefully will make this library React Native compatible?