-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Labels
bugsomething brokensomething broken
Description
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: #5119.
Reproducible example
- Create an app with
create-react-app
. - 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
. - Run
yarn start
in the project directory.
Screenshot
Expected output
The app runs well without terminal or browser errors.
Actual output
Error inside browser window:
Update
The essence of this issue is here: #5243 (comment)
Metadata
Metadata
Assignees
Labels
bugsomething brokensomething broken
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
silviubogan commentedon Nov 3, 2020
Sorry, I think it is a configuration problem on my side. It seems to work with create-react-app. I am closing this because of this.
silviubogan commentedon Nov 9, 2020
I get the same error again and in a similar situation, so I think it is real. This time I have more information. We use
plotly.js 1.57.0
andreact-plotly.js 2.5.0
. The code is here and the situation in images is:Browser window contents
DevTools console
react-plotly.js errors
Our code's errors
plotly.js errors
I will try to reproduce this issue in a
create-react-app
project and come with an update.Thank you.
silviubogan commentedon Nov 9, 2020
I think that the following error might be related to the same issue:

silviubogan commentedon Nov 9, 2020
I have tested and the screenshot in my message above is the root cause of this issue.
In chronological order:
[-]image-size dependency makes plotly.js not work in browser through webpack[/-][+]ReferenceError: document is not defined[/+]archmoj commentedon Nov 9, 2020
@silviubogan could you investigate if probe-image-size depends on
fs
? And if it does not, can we replaceimage-size
here?plotly.js/src/traces/image/helpers.js
Line 11 in e62219a
silviubogan commentedon Nov 9, 2020
In our code, the issue is that these instructions (just them, as I verified), when not commented out, produce the error related to the
fs
module, although I was thinking this is impossible since I tested them in a context where they are not used anywhere:I still do not understand how
loadable.lib
works. I thought it lazy loads the libraries, so if none of theconst
s above are used, as I tested, the error related tofs
is not justified.I start investigating the probe-image-size library now, if nothing else more important intervenes.
Thank you!
silviubogan commentedon Nov 9, 2020
The
probe-image-size
library does not requirefs
and, they say, finds the length only through HTTP. An example usage is this:(via this link)
But its internal functions are easy to use and extend. If time allows me to do this, I can try to use it for your use cases.
nicolaskruchten commentedon Nov 10, 2020
I could be way off the mark here but the
document is not defined
error suggests to me that you're trying to use this module in a NodeJS context rather than a browser context, which is not really a supported use-case at all... Is that indeed what you're trying to do?silviubogan commentedon Nov 10, 2020
Yes, more precisely we use razzle with SSR. I hope that SSR is supported.
Thank you.
nicolaskruchten commentedon Nov 10, 2020
Unfortunately, pure-Javascript SSR is not officially supported at this time and I'm not aware of anyone having successfully done it unofficially, due to this exact issue. Plotly.js relies extensively on browser APIs which are generally not available or hard to emulate on the server short of running a full in memory browser like we do in the Kaleido project.
silviubogan commentedon Nov 24, 2020
PTAL and help me solve this issue. Is it an issue in
@loadable/component
?silviubogan commentedon Nov 24, 2020
It seems that after commenting all the other loadable.lib calls in the message above, from these remaining two:
the first one alone does not produce the error with
fs
, but when uncommenting the second one, the error is there. What could be the issue? Is it a Loadable issue?Thank you.
archmoj commentedon Jan 8, 2021
@silviubogan would you mind testing if the issue was resolved after #5388?
silviubogan commentedon Jan 8, 2021
@archmoj Thank you for the notification. I am pleased to know you have worked on this. I will try to find time in the following week.
archmoj commentedon Jan 9, 2021
See #5377 (comment)
silviubogan commentedon Jan 15, 2021
@archmoj The error related to the module
image-size
is gone (with the latest commit inplotly.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!archmoj commentedon Jan 15, 2021
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.