-
Notifications
You must be signed in to change notification settings - Fork 103
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
d3-format@1.4.2 sideEffects:false breaks graph axis formatting #84
Comments
My understanding is that sideEffects: false is intended to mean there are no side-effects that cross modules, not that there are no side-effects within the module. That d3-format has an internal side-effect does not violate the intent of “sideEffects: false”. What are you using to compile your code? |
We're using stock Angular 7.2.15, typescript 3.2.4, node v10.16.3, npm 6.9.0. The failure comes in this (pseudo)code:
The error is:
I instrumented various functions in the d3 ecosystem, and determined that The only production change that I see between d3-format v1.4.1 and v1.4.2 is the addition of the |
Here's a link to the webpack docs that may help: https://webpack.js.org/guides/tree-shaking/#mark-the-file-as-side-effect-free To quote:
I would think that some global variable initialization would meet this definition of "side effect". |
Angular’s optimizer is known to break code, and they don’t appear to have plans to fix this behavior. This has affected other D3 libraries (e.g., d3/d3-color#68 (comment)), and may be the cause of what’s happening here. This change to add sideEffects: false was suggested by a Webpack maintainer; see d3/d3#3131. I don’t personally use Webpack, and I find the documentation to be somewhat ambiguous (does a “module” mean any individual file, as in ES modules, or do they mean the package in total, as in npm & node_modules?). I don’t know how to determine what is appropriate here. From my perspective, the only thing adding sideEffects: false has brought is an influx of issues from Angular users. (Sorry for the gripe!) |
Proposed fix in #85. I think we’ll need a similar fix for d3-time-format. |
No response, but I merged #85, so I’ll publish that and see what happens. |
Thanks for the quick resolution on this, and Happy New Year! ❤️ |
d3-format@1.4.2 sideEffects:false breaks graph axis formatting
The d3-format
src\defaultLocale.js
callsdefaultLocale
at load time. This is, by definition, a side effect of loading the module. As such, it's inappropriate to setsideEffects:false
in thepackage.json
file. I believe that this is the root cause of this issue.For our project compiled for production, d3-format@1.4.2 causes
d3-scale\src\tickFormat.js
to exception when it callsformat()
, because format has not been defined, presumably because webpack's tree shaking has entirely removed d3-format's invocation ofdefaultLocale()
.The docs at https://www.npmjs.com/package/d3-format say this:
However, this is not true when compiling in production mode with d3-format@1.4.2.
When I explicitly install d3-format@1.4.1, or if I explicitly call
d3d3.formatDefaultLocale()
, then I do not get an exception, and my graphs render in my application.The text was updated successfully, but these errors were encountered: