-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Tree shaking and React #1699
Comments
Reason of the issue: Possible solution: Program: {
enter(path, asset) {
asset.cacheData.imports = asset.cacheData.imports || Object.create(null);
asset.cacheData.exports = asset.cacheData.exports || Object.create(null);
asset.cacheData.wildcards = asset.cacheData.wildcards || [];
asset.cacheData.sideEffects = asset._package && asset._package.sideEffects;
path.scope.crawl(); @devongovett @fathyb Do you have any thoughts? 😄 |
@buronnie Thanks for chiming in. Yes, that possibility ran through my mind today as well. The order that the transpilation steps happen will mislead the tree shaking algo in some cases. |
I've updated the test repository to use Parcel Error (from the browser console)
Breakpoint from the bundle file// ASSET: node_modules/core-js/modules/_set-to-string-tag.js
var $iqAm$exports,
$iqAm$var$def,
$iqAm$var$has,
$iqAm$var$TAG,
$iqAm$executed = false;
function $iqAm$init() {
if ($iqAm$executed) return;
$iqAm$executed = true;
$iqAm$exports = {};
$iqAm$var$def = ($wv$init(), $wv$exports).f;
$iqAm$var$has = ($nW2g$init(), $nW2g$exports);
$iqAm$var$TAG = ($Mgd$init(), $Mgd$exports)('toStringTag');
$iqAm$exports = function (it, tag, stat) {
if (it && !$iqAm$var$has(it = stat ? it : it.prototype, $iqAm$var$TAG)) $iqAm$var$def(it, $iqAm$var$TAG, {
configurable: true,
value: tag
});
};
} |
@rafaelrinaldi #1735 and #1737 should fix the |
@devongovett I just tried release 1.9.7 which includes the fix in #1737 . The issue |
The React import error now has a PR #2292. @rafaelrinaldi Now your example throws this: |
🐛 bug report
I am experiencing a faulty behavior when generating a production bundle using the experimental tree shaking feature.
I have already logged this in the Spectrum channel but decided to open a proper bug report as well.
🎛 Configuration (.babelrc, package.json, cli command)
I put together a repository so you can reproduce the same behavior I am experiencing: https://github.com/rafaelrinaldi/parcel-tree-shaking-jsx-error
🤔 Expected Behavior
Tree shaking should work just fine.
😯 Current Behavior
Tree shaking kinda works but seems to bypass React, logging "React is not defined" in the console.
💁 Possible Solution
I believe that this could be two of the following:
babel-plugin-transform-react-jsx
plugin added by thebabel-preset-react
should be replacing JSX nodes byReact.createElement()
calls, therefore notifying the tree shaking algorithm that the module is being used)🔦 Context
I'm trying to get the experimental tree shaking feature to work in a project that uses a route-based code splitting strategy using react router and react loadable.
💻 Code Sample
I put together a repository so you can reproduce the same behavior I am experiencing: https://github.com/rafaelrinaldi/parcel-tree-shaking-jsx-error
🌍 Your Environment
The text was updated successfully, but these errors were encountered: