ReactNativeJS: ReferenceError: Can't find variable: document

Asked
Active3 hr before
Viewed126 times

8 Answers

variablereferenceerror
90%

Error : ReactNativeJS: ReferenceError: Can't find variable: document,Asking for help, clarification, or responding to other answers.,Making statements based on opinion; back them up with references or personal experience.

In WebView, you can inject Script as below

<WebView
 source={{ uri: this.url }}
 ref='WEBVIEW_REF'
  injectJavaScript={
   "window.testMessage = 'hello world'"
  }
/>
load more v
88%

[JS Polyfills] Can't find variable: document (potential need for document polyfill). mkonicek. Moved from https://github.com/facebook/react-native/issues/1495.,Bug Getting "Can't find variable: document" error when launching React-Native app with storybook. Simple sanity test would help a lot here.,i am trying to run react native project with expo XDE but i am getting this error can't find variable symbol i have tried babel poly fill method and

Pretag
 Pretag team - issue, fix, solve, resolve
72%

Using transform-remove-console triggers ReactNativeJS: ReferenceError: Can't find variable: error only on production build,This is not happening on development build if i add the same transform plugin in development mode. Also, this is not happening when i add { exclude: ["error", "warn"] } options to the transform plugin,By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

const plugins = ["react-native-paper/babel"];
if (process.env.NODE_ENV === "production") {
   plugins.push(["transform-remove-console"]);
}

module.exports = {
   presets: ["module:metro-react-native-babel-preset"],
   plugins: plugins
};
load more v
65%

1 ReactNativeJS: ReferenceError: Can't find variable: document,I'm trying to integrate wavesurfer.js (http://wavesurfer-js.org/docs/) into a ReactNative app but I'm getting a Component Exception: Can't find variable: document.,So once again, is there any way to use wavesurfer.js without adjusting its code? And if not, what changes would I have to make to it?

The salient parts of my App.js file is:

    import React from 'react';
    import { Appbar } from 'react-native-paper';
    import { Button } from 'react-native-paper';
    import Icon from 'react-native-vector-icons/MaterialIcons';
    import { Colors } from 'react-native-paper';
    import WaveWrapper from './wavewrapper.js';

    const App: () => React$Node = () => {
      return (
    //..
    <View style={styles.eqContainer} nativeID="eqview">
        <WaveWrapper />
    </View>
    //..
      );
    };
    export default App;
load more v
75%

Pretag
 Pretag team - issue, fix, solve, resolve
40%

Problem: https://stackoverflow.com/questions/62768740/referenceerror-cant-find-variable-domparser I’m parsing a fetched html string into DOM object for cross-platform React Native app.,I’ve tried storing global’s DOMParser into a variable to force reference pointing. But this attempt gives me another error: TypeError: undefined is not a constructor. This made me think that expo does not support DOMParser. I cannot seem to find the same error that I am experiencing even after long hours of googling. Please help! ,And, what a coincidence, as I was waiting for someone to reply, I went ahead to try JSDOM but then Expo specifically warns staying away from packages utilizing Node standard library with this warning, just to share with you:

Pretag
 Pretag team - issue, fix, solve, resolve
22%

ReferenceError: Can't find variable: Element, ReferenceError: Can't find variable: Element ,function-plot runs wherever the DOM API is available, unfortunately, React Native JS runs in a place where the DOM is not available, you could use a webview https://github.com/react-native-webview/react-native-webview as a workaround

where functionPlotWebview.html is something like this:

<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
    <p>Hello World<p>
    <script src="https://unpkg.com/function-plot/dist/function-plot.js">
    </script>
    <script>
         functionPlot({
          target: '#quadratic',
          data: [{
            fn: 'x^2'
          }]
        })
    </script>
</body>
</html>
load more v
60%

react-native-code-push version: 7.0.0,instead of this as in documentation,Install new build and then codepush.

Pretag
 Pretag team - issue, fix, solve, resolve

Other "variable-referenceerror" queries related to "ReactNativeJS: ReferenceError: Can't find variable: document"