Native ES6 modules vs. the bundle
See original GitHub issueWhen plotly.js
is loaded in Chrome by the native ES6 import
, the loading crashes with Cannot read property 'document' of undefined
at line 18178
, i.e. at var d3_document = this.document;
The problem is that the bundler assumes that when a function is executed without any this
, the this
will automatically be set to window
. This is not the case with ES6 modules, where this
will be undefined.
I fixed it by changing line 27724
from }();
to }.apply(self);
but this is just a hack 😃
Issue Analytics
- State:
- Created 5 years ago
- Reactions:21
- Comments:41 (7 by maintainers)
Top Results From Across the Web
Using Native, Unbundled ES6 Modules With a Simple Build ...
Native module loading According to Google Chrome's Platform Status, less then 4% of page loads use it! Most resources I've found use bundlers...
Read more >ES6 browser support: is it time to rethink bundling? - Contentful
The new setup using native supported ES6 modules. Now that we have the “traditional bundle” for all the browsers that don't support ES6...
Read more >Using Native JavaScript Modules in Production Today
In the rest of this post I'm going to show you how I bundle to modules (including the use of dynamic import and...
Read more >Demystifying Code Bundling with JavaScript Modules
Dependencies are modules, too, which means they no longer need to be loaded individually before the main file can load. The bundle is...
Read more >Webpack vs ES6 modules - Stack Overflow
Also, Webpack version 5 appeared which provides module federation feature where you can use part of code from one bundle into another. which...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Is there a ‘real’ solutions for this available? I’d like to use Plotly for an Angular 8 project - but reverting to es5 is not really an option (it will break for Angular 9 I think). I was so hoping to use plotly as a Highchart replacement - but no dice I’m afraid.
@jmsuresh In this file:
https://cdnjs.cloudflare.com/ajax/libs/plotly.js/1.49.1/plotly.js
search for
define(d3)
. You will find:Change
}();
to}.apply(self);