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.

ReferenceError: document is not defined

See original GitHub issue
doc = document,
                  ^
ReferenceError: document is not defined

Seems to be an issue when trying to run this using an isomorphic app

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:23 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
joshhornbycommented, Jul 16, 2015

With the help of @Kureev I seem to hack a (hacky) fix

import React from 'react';

export default class HighchartGraph extends React.Component {

    render() {
      let graph;

      if(window === undefined) {
        graph = (<div></div>);
      } else {
        var Highcharts = require('react-highcharts/more');
        graph = (<Highcharts config={this.props.chartData}></Highcharts>)
      }

      return (
          <div>
            {graph}
        </div>
      );
    };
}

This seems to have fixed the issue. I would still love to see @0xCMP custom component though 😃

0reactions
duongthienleecommented, May 5, 2019
`import { canUseDOM } from 'fbjs/lib/ExecutionEnvironment';
`

Use this one may help. https://github.com/kriasoft/react-starter-kit/issues/186#issuecomment-131742615

Read more comments on GitHub >

github_iconTop Results From Across the Web

ReferenceError: document is not defined in JavaScript
The "ReferenceError: document is not defined" error occurs for multiple reasons: ... The document relates to the document object which represents a web...
Read more >
ReferenceError: document is not defined (in plain JavaScript)
Explanation: The error is caused because NextJs renders the page in the server only and in the server document (document is used inside...
Read more >
How to fix ReferenceError: Document is not defined ... - Sabe.io
The most common reason for getting the reference error while on the browser is when you try to access the document object too...
Read more >
How To Fix ReferenceError document is not defined ... - Isotropic
If you are trying to use the document object and receiving a ReferenceError: document is not defined error then there is a good...
Read more >
How to solve the document is not defined error - Flavio Copes
Here's how to fix the “referenceerror: document is not defined” error that you might have in Node.js or with a tool like Next.js....
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