-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Native ES6 modules vs. the bundle #3518
Native ES6 modules vs. the bundle #3518
Comments
Thanks for writing in.
Can you share a reproducible example of how you're going about doing this. Thank you! |
Try:
or alternatively:
|
In a codepen: https://codepen.io/alexcjohnson/pen/aXEbOa?editors=1011 That particular error is with d3v3 - seems like v4 fixes it so we should get it when we leapfrog to v5. Will be interesting to see if there's anything else in our code that uses |
Can you please provide which particular line had to be changed. I am stuck with this for the past two days (tried many things with babel options - nothing worked) |
Any fix for this? |
Fix for version 1.48.2; the change is at line number 32481 '/node_modules/plotly.js/dist/plotly.js' |
Anybody know if there is a issue for this filed in the d3 project? |
@jmsuresh In this file: https://cdnjs.cloudflare.com/ajax/libs/plotly.js/1.49.1/plotly.js search for
Change |
From #4130 @Arjun-Shinojiya wrote:
Maybe someone here can help. |
@oldrich-svec can you please tell the exact location of the file which you mentioned in this questions last line? .I am facing the same issue. |
see #3518 (comment) |
So I should use plotly.js via CDN in angular 8 right? |
@Arjun-Shinojiya it is up to you how you use plotly.js ;). The comment just shows you what line you want to edit. |
Is editing the line of code the only solution? What happens when I want to upgrade to a new version of plotly? I have to edit it every time? |
@TravisLRiffle yes you have to reapply your hack every time! For me, it is not a solution for enterprise applications. |
After fixing this, I got a d3_xhr-not found-error although it's defined |
Alternative workaround for Angular 8 upgraders: For those of us coming here having encountered this issue when upgrading to Angular 8, an alternative workaround solution to editing the plotly.js file is to not use the new "Differential Loading by Default" as mentioned in this comment on angular-plotly.js: plotly/angular-plotly.js#75 (comment)
So changing the following property in the tsconfig.json file hides the issue: |
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. |
Just tried with the current latest version (1.52.2), and it's still broken. We have a large Angular-based application, that we cannot update because of this issue. :( |
First, I would recommend taking a look at https://github.com/plotly/angular-plotly.js as that is apparently working with Angular 8.x+. Otherwise, if it is an option for your project, I would recommend loading plotly.js via the CDN. |
I managed to get it working in ng9 with ivy by including plotly.min.js as a regular script reference on the page and then Used angular.json to copy it to assets from the node_modules. |
@fourgates I am using Plotly.js 1.54.5 with angular-plotly.js 2.0.0 in Angular 10 successfully. The property read issue only occurred when
|
@oldrich-svec have you tried the above solution? |
I have just tried to execute v1.54.7 code as described in #3518 (comment) and yes it is still failing with
I do not use Angular so I did not test the above solution. If I am not mistaken, all the solutions are either
|
This issue has been tagged with A community PR for this feature would certainly be welcome, but our experience is deeper features like this are difficult to complete without the Plotly maintainers leading the effort. Sponsorship range: $10k-$15k What Sponsorship includes:
Please include the link to this issue when contacting us to discuss. |
Looks like plotly needs to upgrade d3 to at least v4 |
(This isn't just an angular issue, all the codesandbox URLs on https://github.com/plotly/react-plotly.js are having this now) Could anyone here get a working version of typescript + plotly.js on code sandbox? All versions of those are failing as well. (for the sake of demos on this project and others) |
@tony same issue here. Cannot use |
OP's fix works for me. Should there be a PR for this? |
I haven't been able to use the precompiled bundles in a Svelte+rollup application that I've been building, but I have been able to use the ES6 module e.g. import replace from "@rollup/plugin-replace";
export default {
....
plugins([
replace({
"}()": "this.d3 = d3;\n}.apply(self);",
delimiters: ["this.d3 = d3;\n", ";"],
}),
...
])
} I can't use error
|
Related: https://community.plotly.com/t/issue-in-electron-built-version/31303/5 (although this fix of marking as external does not work for me). |
Solution for const StringReplacePlugin = require("string-replace-webpack-plugin");
module.exports = {
chainWebpack: config => {
config.module
.rule('plotly')
.test(/plotly\.js$/)
.use('stringreplace')
.loader(StringReplacePlugin.replace({
replacements: [
{
pattern: /module.exports = d3; else this.d3 = d3;\n}\(\);/,
replacement: function() { return 'module.exports = d3; else this.d3 = d3;\n}.apply(self);' }
}
]}))
.end()
}
}; |
Seems it is not going to be fixed even in v.2.0.0 :(. So if anybody needs to fix this in minified version, look for:
and replace it with:
|
In v2 we are no longer exporting d3 so we will have a path towards upgrading it to a version that doesn't suffer from this problem, but indeed, this current problem doesn't automatically go away in v2. |
…otly.js#3518) FIX: golden-layout styles import.
If anyone wants to implement the change in node_module and use a much more radical approach, leverage the patch-package utility. In package.json scripts, one can use it following command to patch the node_modules
The patches for plotly 1.58.4 diff --git a/node_modules/plotly.js/dist/plotly-with-meta.js b/node_modules/plotly.js/dist/plotly-with-meta.js
index 1aaac5a..cb3ecfe 100644
--- a/node_modules/plotly.js/dist/plotly-with-meta.js
+++ b/node_modules/plotly.js/dist/plotly-with-meta.js
@@ -35864,7 +35864,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
return request.responseXML;
});
if (typeof define === "function" && define.amd) this.d3 = d3, define(d3); else if (typeof module === "object" && module.exports) module.exports = d3; else this.d3 = d3;
-}();
+}.apply(self);
},{}],170:[function(_dereq_,module,exports){
module.exports = function () {
for (var i = 0; i < arguments.length; i++) {
diff --git a/node_modules/plotly.js/dist/plotly.js b/node_modules/plotly.js/dist/plotly.js
index 365230c..6268511 100644
--- a/node_modules/plotly.js/dist/plotly.js
+++ b/node_modules/plotly.js/dist/plotly.js
@@ -35864,7 +35864,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
return request.responseXML;
});
if (typeof define === "function" && define.amd) this.d3 = d3, define(d3); else if (typeof module === "object" && module.exports) module.exports = d3; else this.d3 = d3;
-}();
+}.apply(self);
},{}],170:[function(_dereq_,module,exports){
module.exports = function () {
for (var i = 0; i < arguments.length; i++) { The patches for d3 3.5.17 diff --git a/node_modules/d3/d3.js b/node_modules/d3/d3.js
index aded45c..d5b3cad 100644
--- a/node_modules/d3/d3.js
+++ b/node_modules/d3/d3.js
@@ -9551,4 +9551,4 @@
return request.responseXML;
});
if (typeof define === "function" && define.amd) this.d3 = d3, define(d3); else if (typeof module === "object" && module.exports) module.exports = d3; else this.d3 = d3;
-}();
\ No newline at end of file
+}.apply(self); |
When
plotly.js
is loaded in Chrome by the native ES6import
, the loading crashes withCannot read property 'document' of undefined
at line18178
, i.e. atvar d3_document = this.document;
The problem is that the bundler assumes that when a function is executed without any
this
, thethis
will automatically be set towindow
. This is not the case with ES6 modules, wherethis
will be undefined.I fixed it by changing line
27724
from}();
to}.apply(self);
but this is just a hack :)The text was updated successfully, but these errors were encountered: