-
Notifications
You must be signed in to change notification settings - Fork 14k
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
fix(plugin-chart-handlebars): Update webpack/babel config to fix build/runtime warnings/errors #21779
Conversation
Codecov Report
@@ Coverage Diff @@
## master #21779 +/- ##
==========================================
- Coverage 66.88% 66.85% -0.03%
==========================================
Files 1800 1803 +3
Lines 68967 68998 +31
Branches 7339 7350 +11
==========================================
+ Hits 46128 46131 +3
- Misses 20943 20972 +29
+ Partials 1896 1895 -1
Flags with carried forward coverage won't be shown. Click here to find out more.
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
@codyml When I looked into the dependency that Just Handlebars Helpers, it said that A lightweight package with common Handlebars helpers. from the npm registry description. It just provided some shortcuts for the IMO, I would rather remove the |
I believe there's actually an open PR out there to do exactly this: #21143 (the discussion there is pretty similar to what you're proposing). I think this comes down to whether or not we feel maintaining these helpers ourselves is something we want to do or not. Normally I'd say let's just use the npm package, but if using the upstream package requires us to do hacky workarounds, then I'm not so sure. |
Heya @zhaoyongjie / @villebro It's true, I don't like the idea of copying over all the internals of that helper module into our codebase for a couple of reasons:
So, I'd like to use this I'll open up an Issue on the However, the big question I have is: do we see any realistic risk or downslides to this change in babel config? Maybe we can approve/merge this until the day that Total side note: Apologies to Evans, who gets pinged by this project all the time, and is not me ;) |
@zhaoyongjie @villebro @rusackas If it helps, I just pushed a diff that overrides the Babel |
Thanks! I spent a few minutes looking for a way to do that, but didn't see one! This looks good to me! |
I really wanted to say sorry to Evan, and buy him a drink. |
🏷️ preset:2022.41 |
…d/runtime warnings/errors (apache#21779) (cherry picked from commit d5b4bde)
SUMMARY
This PR is an attempt to fix the Handlebars viz plugin, which currently raises both build and runtime errors, by updating Webpack and Babel config.
Build warning
Webpack would emit the following warning several times during build:
require.extensions is not supported by webpack. Use a loader instead.
. The source listed was various lines in./node_modules/handlebars/lib/index.js
. According to the Handlebars GH project, this is due to the package not correctly indicating which build is client-side-compatible. A fix was merged, but it hasn't made it into an NPM-published release. A workaround was recommended by this comment and is included in this PR. This issue doesn't seem to be related to the runtime error and this fix just clears the build warning.Runtime error
When rendering a Handlebars chart in Explore, the following error appears:
ReferenceError: exports is not defined
. An inspection of the console shows that the culprit is thejust-handlebars-helpers
package's references toexports
, as is standard in the CJS module system. After some digging, I found this comment that makes me think the problem is a CJS/ESM incompatibility: our Babel setup assumes all JS is ESM-style modules and therefore doesn't transpile CJS-stylerequire
andmodule.exports
statements intoimport
/export
statements, and Webpack assumes Babel output is ESM-style modules and doesn't provide globalrequire
/module.exports
that you'd find in a CJS environment, causing this error (just-handlebars-helpers
seems to be CJS-only). As suggested by the comment, I changedsourceType
tounambiguous
so it stops assuming modules are ESM-style and instead makes a guess based on the presence ofrequire
/module.exports
. This seems to fix the issue, though I don't have a great sense of what else this might affect.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Before:
After:
TESTING INSTRUCTIONS
ADDITIONAL INFORMATION