antvis/G2

Document is not defined #2534

MarkLyck posted onGitHub

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.


Fund this Issue

$0.00
Funded

Pull requests