I’m using the plotly.js library to display charts in my application. While the library works fine when running either
serve script, the
build script, or the
electron:serve scripts, everything works just fine. However, when I build the application using
electron:build , Electron fails to load the webpage. The console contains the error message
cannot load property 'document' of undefined caused by the line of code displayed in the screenshot. This line of code has been directly lifted from the
plotly.js file found within the package.
To reproduce the error, simply create a new project using vue cli, and then add the plugin electron-builder which will take care of everything. Then install
plotly.js-dist and try to display a chart in the main component. The resulting built application (AppImage) gives a blank page with the following error:
I dug around a bit and it seems that the strict mode used in the built version of plotly is causing the issue, since
this has not been yet binded to anything. I tried to look for a version of plotly that came with D3 as its dependency and not built into it, hoping that the build system can deduce the right course of action, but there doesn’t seem to be any.
I’d really appretiate your help. Plotly is crucial to my application and I really don’t see any alternative for it.