plotly.js: ReferenceError: document is not defined

This dependency makes it impossible to use plotly.js in the browser because image-size uses fs module which is not available in browsers. I do not know how does react-plotly.js adapt to this dependency but I guess they have this issue too.

Related to: https://github.com/plotly/plotly.js/pull/5119.

Reproducible example

  1. Create an app with create-react-app.
  2. Install dependencies from the screenshot below (you might need to change the React and ReactDOM packages’ versions too), including plotly.js@1.57.1 and use it as a dynamic import with @loadable/component.
  3. Run yarn start in the project directory.

Screenshot

image

Expected output

The app runs well without terminal or browser errors.

Actual output

Error inside browser window:

image

Update

The essence of this issue is here: https://github.com/plotly/plotly.js/issues/5243#issuecomment-724028727

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 17 (6 by maintainers)

Most upvoted comments

@archmoj The error related to the module image-size is gone (with the latest commit in plotly.js#master) in the project I work on, although I did not test inside CodeSandbox. Is it possible to tell when will the change be included in a GitHub release? Thank you!

Thanks for testing this out. We are working on a major release now that involves days of QA. So v2 might be out around Jan 25, I hope.

@silviubogan would you mind testing if the issue was resolved after #5388?