New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
can't find variable: document #35
Comments
I haven't tried I'm not sure what to recommend here, since this seems likely to be an issue with Emscripten itself. The unsatisfactory answer is that we don't currently support React Native :/. |
Hey I have found a workaround. If I comment out the following code in if (document.currentScript) {
scriptDirectory = document.currentScript.src;
}
Module["setWindowTitle"] = function (title) {
document.title = title;
}; everything works as expected. This does feel quite hacky so I was wondering if there was a better way to remove the document dependency? It doesn't seem to have any real functional use in the code. |
AFAIK, this is not used - it's part of the Emscripten boilerplate. I can see whether there's a clean way to remove this in the build, but in the meantime, it might be less hacky to polyfill document with |
OK, thanks. Right now I'm still trying out this library but I'll be sure to test your solution and report back. |
any update on this? |
I haven't gone into production yet so I'm still using the hack. The polyfill solution does sound promising though. |
I hit this today too and have a workaround that seems fine. In RN you can use In App.js global.document = {};
export default App = () => (...) then in AnyFile.js import and use h3 as normal import { h3ToGeo } from "h3-js";
const hexID = geoToH3(longitude, latitude, 7); |
There's a fork here that fixes the distro package for React Native. I'm closing this for now, as RN support isn't in scope for |
I have the same problem on a web app. I'm trying to use h3-js in a web worker.
Should I open a new issue? |
@len-art I don't think web workers have a global let document = {};
// some code using h3
// the rest of your web worker code I haven't done that, but that's all h3 needs. It doesn't need any members of |
Workers don't have a global |
@len-art have you figured out how to solve this issue in a webpack-compiled webworker? I am facing the same problem and was not able to solve it easily bu setting |
@benjamintd sorry for responding so late: No, I haven't. I went another route and implemented something different which, in retrospect, made more sense than using H3. Regardless, I would really love it if the authors would fix this problem. There are a ton of use cases for H3 that benefit from being calculated in a separate thread. |
Thanks @len-art for following up! I ended up going the ugly way and using
I would gladly have sent a PR to h3-js directly, but it seems that it would involve changing the docker image that runs emscripten build. I did not have time to dig further. |
There's definitely plenty of use cases where using h3-js in web workers makes total sense. Something apparently simple like the following is blocking the execution of main thread, making the map unresponsible during 3/4 seconds (neither being able to show a spinner). import { cellToBoundary, polygonToCells } from 'h3-js';
import { polygon as toPolygon } from '@turf/turf';
import type { Slope } from './types';
onmessage = (event: MessageEvent<{ slopes: Slope[], resolution: number }>) => {
const { slopes, resolution } = event.data;
const cells = slopes.flatMap(slope => {
const { coordinates, type } = slope.feature.geometry;
const polygons = type === 'MultiPolygon' ? coordinates : [coordinates];
const h3Ids = polygons.flatMap(polygon => polygonToCells(polygon, resolution, true));
return h3Ids.map(id => toPolygon([cellToBoundary(id, true)], { id }));
});
postMessage(cells);
}; I've tried to just fake a global document object as suggested, without success. Just for context, I'm using Vite. |
Sorry, this is still on my TODO list. It's likely solved by a more recent version of Emscripten, but I believe that's still blocked on performance regressions, making this a potentially difficult update. |
I'm trying to us the h3-js library in a react-native app. I npm installed the library, and then when I just import h3 into one of my files, it gives me an error that say's can't find variable document. I'm assuming it is coming from the libh3.js file in "./dist/out" where it has the function....
var libh3 = (function() {
var _scriptDir = typeof document !== 'undefined' && dtocument.currentScript ? document.currentScript.src : undefined;
return (
........
I don't know where the problem is coming from but it's not in my code because I'm just trying to import h3-js
The text was updated successfully, but these errors were encountered: