GithubHelp home page GithubHelp logo

Comments (17)

4nthonylin avatar 4nthonylin commented on July 19, 2024 2

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 :)

from h3-js.

corbt avatar corbt commented on July 19, 2024 1

It looks like the bug on the Emscripten side (emscripten-core/emscripten#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?

from h3-js.

padawannn avatar padawannn commented on July 19, 2024 1

It looks like the bug on the Emscripten side (emscripten-core/emscripten#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?

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

from h3-js.

cnrdh avatar cnrdh commented on July 19, 2024 1

With Deno's recent support for npm packages, you may now use a regular import like

import * as h3 from "npm:[email protected]";

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.

from h3-js.

nrabinowitz avatar nrabinowitz commented on July 19, 2024

See #35 - this is a known issue. We're not currently targeting React Native; I'd like this to work, obviously, but the issue is deep in the emscripten internals and hard to remove. There's a fork here that tries to address this, but I haven't had time to see if it can be fixed in the main library, and I don't have a great way to test the fix.

from h3-js.

johhnsmmith198 avatar johhnsmmith198 commented on July 19, 2024

A very simple way to fix it is to change the generated code in dist from:

  
    if (document.currentScript) {
      scriptDirectory = document.currentScript.src;
    }

to

 if (ENVIRONMENT_IS_WEB) {
      if (document.currentScript) {
        scriptDirectory = document.currentScript.src;
      }
    }

Note that ENVIRONMENT_IS_WEB should be defined. I think it is generated by emscripten => emscripten-core/emscripten#6717

I created an issue on their github

from h3-js.

dfellis avatar dfellis commented on July 19, 2024

I will note that the reason why emscripten was not updated for this project was due to performance regressions with asm.js compilation on newer releases of emscripten than the version that is in use (likely due to asm.js being a less-common usage of emscripten these days).

Upgrading emscripten is not without trade-offs.

from h3-js.

corbt avatar corbt commented on July 19, 2024

I will note that the reason why emscripten was not updated for this project was due to performance regressions with asm.js

Oh interesting, I wasn't aware! Are there benchmarks for how large the impact would be on this library if it adopted the latest emscripten? Making this compatible with h3 would be really nice, but of course not at the cost of a significant performance regression for other users!

from h3-js.

dfellis avatar dfellis commented on July 19, 2024

It was a few years ago that we noticed the regression. I searched but couldn't find the benchmark we did back then. As I recall some functions were unaffected but most functions were 10-20% slower and a few were more than 50% slower but since it has literally been years in the meantime, it's probably a good idea to try again and re-benchmark against the current version of emscripten.

from h3-js.

lofsigma avatar lofsigma commented on July 19, 2024

I would also be interested in a version of h3-js that works on the server.
I tried updating to the latest version of Emscripten to at least get a benchmark but I couldn't get it to work.

  • MODULARIZE_INSTANCE=1 is deprecated so you have to use MODULARIZE=1 instead, which returns a function which returns a promise that resolves to an instance.
  • Also I think you need to explicitly export _free now.

from h3-js.

nrabinowitz avatar nrabinowitz commented on July 19, 2024

I would also be interested in a version of h3-js that works on the server.

To be clear, h3-js works fine on a server running Node. It only has issues running in React Native.

from h3-js.

lofsigma avatar lofsigma commented on July 19, 2024

Sorry I misspoke. It doesn't work with vercel's edge runtime / middleware.
Same error as react native.

ReferenceError: document is not defined

from h3-js.

nrabinowitz avatar nrabinowitz commented on July 19, 2024

Thanks for the clarification, that's good to know.

from h3-js.

cnrdh avatar cnrdh commented on July 19, 2024

This issue will bite any JavaScript runtime that has no global document.
For Deno I found a workaround a while ago that involved dynamic import:

const document = {};
const h3 = await import("https://esm.sh/[email protected]");
const h3Index = h3.latLngToCell(37.3615593, -122.0553238, 7);
console.warn(h3Index);
// 87283472bffffff

from h3-js.

kenjinp avatar kenjinp commented on July 19, 2024

I've encountered this issue when trying to use h3 inside a web-worker as well; edited, I didn't see @padawannn 's comment :)

from h3-js.

nrabinowitz avatar nrabinowitz commented on July 19, 2024

Related discussion, with benchmarks for the emscripten upgrade issue: #163 (comment)

from h3-js.

nrabinowitz avatar nrabinowitz commented on July 19, 2024

Thanks @4nthonylin! Closing for now - there may be other blockers for React Native or unusual environments, but hopefully this is a reasonable fix for many of the affected situations.

from h3-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.