-
-
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 does not work with Material UI #1984
Comments
I confirm the issue. I can reproduce it too. |
With tree shaking enabled, I only get this error:
|
Can someone verify this in the latest version of Parcel? |
With the latest version of Material-UI (v4.0.0-alpha). We have changed the tree shaking strategy. |
import { Typography } from '@material-ui/core'
console.log(Typography) trying to build with scope hoisting:
Commenting out the import React from 'react'
import { render } from 'react-dom'
import Typography from '@material-ui/core/Typography'
render(
<Typography>Hello</Typography>,
document.getElementById('app')
) ->
|
(The corresponding code is all in transitive dependencies) @devongovett This is caused is by this bit ( var _hyphenateStyleName = require('hyphenate-style-name');
var _hyphenateStyleName2 = _interopRequireDefault(_hyphenateStyleName);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
// ...
(0, _hyphenateStyleName2['default'])(prop) The |
cc @kof (just for context) |
Also having this issue, I was a bit surprised having 5MB increased bundle size for two icons 😂 |
@gisderdube Does it work better with v4-alpha? |
Didn't check with v4 alpha, but with |
Should be fixed by #2993. |
Sorry for pinging this old issue, but tree shaking is still not working with Material UI in Parcel 2 for me. As soon as I do something like Is there any CLI flag or extra configuration that we're supposed to be doing in v2? |
🐛 bug report
When using
--experimental-scope-hoisting
with@material-ui/core
, the bundle builds with no errors. However, when the app is served fromindex.html
, its fails withReferenceError: React is not defined
. Tried both CJS and ESM, same error. When the flag is not used, it builds and runs fine. I also ran into a similar issue with@material-ui/icons
; the error isTypeError: (0 , Oj.default) is not a function
. See code samples and metrics in the gist.🎛 Configuration (
.babelrc
,package.json
)🤔 Expected Behavior
It should render with no JavaScript errors in the console.
😯 Current Behavior
It fails to render with
Uncaught ReferenceError: React is not defined
. Blank screen, nothing is displayed.🔦 Context
I was curious to see if Parcel
1.9.x
supports tree shaking with Material UI. With Webpack, tree shaking doesn't seem to work for CJS, but does work with ESM (which MUI exports for evergreen browsers). fuse-box produced heavy bundle size (maybe I was using it wrong with Babel); I'm yet to try out with Rollup.💻 Code Sample
👉 Please see the gist for details. 👈
🌍 Your Environment
P.S. I understand it's an experimental feature; just wanted to bring up a real word scenario where it falls short :-) Thanks
The text was updated successfully, but these errors were encountered: