ReactNativeJS: ReferenceError: Can't find variable: document

Active3 hr before
Viewed126 times

8 Answers


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

 source={{ uri: this.url }}
   "window.testMessage = 'hello world'"
load more v

[JS Polyfills] Can't find variable: document (potential need for document polyfill). mkonicek. Moved from,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 team - issue, fix, solve, resolve

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") {

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

1 ReactNativeJS: ReferenceError: Can't find variable: document,I'm trying to integrate wavesurfer.js ( 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 />
    export default App;
load more v

 Pretag team - issue, fix, solve, resolve

Problem: 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 team - issue, fix, solve, resolve

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 as a workaround

where functionPlotWebview.html is something like this:

<!DOCTYPE html>
<html lang="en">
    <p>Hello World<p>
    <script src="">
          target: '#quadratic',
          data: [{
            fn: 'x^2'
load more v

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

 Pretag team - issue, fix, solve, resolve

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