question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

React-native won't compile because of the use of h3-js

See original GitHub issue

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 = "";
    }

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:13

github_iconTop GitHub Comments

1reaction
cnrdhcommented, Oct 21, 2022

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

import * as h3 from "npm:h3-js@4.0.1";

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.

1reaction
corbtcommented, May 24, 2022

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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

can't compile and run my react native app #25936 - GitHub
I just can't compile and run my react native app, and I'm getting this message : FAILURE: Build failed with an exception.
Read more >
Troubleshooting Native Modules · React Native for Windows + ...
My native method isn't being hit in the VS debugger. If your method isn't being hit in the VS debugger, something is blocking...
Read more >
Failure to compile on react native - javascript - Stack Overflow
So I've been trying to run my react native code but it keeps ... This method is required in order to use this...
Read more >
React Native compile time errors not resulting in run time failure
I've configured a React Native app via the react-native-cli using the TypeScript template and have been working in the codebase for a few ......
Read more >
React Native: Why and How to Build Your Native Code in Go
We use React Native packages that deal with the native parts of each OS, because core React Native hasn't got to it yet,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found