Document is not defined #2534
MarkLyck posted onGitHub
- G2 Version:4.0.2
- Platform: any
- Mini Showcase(like screenshots):
<img width="1236" alt="Screen Shot 2020-06-02 at 5 05 01 PM" src="https://user-images.githubusercontent.com/6841110/83574505-374ca700-a4f3-11ea-992d-ccce8be5029e.png">
The Antvis G2 library fails when building it in Rollup, or if the package is simply imported in a setup like next.js, Gatsby, Meteor that does both server-side and client-side rendering.
As a user I would not expect G2 to try to render anything if no DOM is available. As a user I would not expect G2 to fail if it's imported in a server-side environment, (simply do nothing or log a warning, but there should be no errors).
Please please add a simple safeguard check at the entry point of G2 that prevents the library from failing if it's read in a server-side environment.
Something like this:
if (!process.browser) {
return undefined
}
This ticket is related to #296, but not asking for a workaround, requesting this to be fixed permanently for everyone allowing BizCharts to be bundled and at least not break when imported serverside.
This ticket is NOT about adding server-side rendering support! Please don't confuse this with a request to make G2 work serverside.
It just shouldn't break the build if document isn't available.