-
-
Notifications
You must be signed in to change notification settings - Fork 32.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
Information: solving jss classnames production build conflict with external MUI dependent component #11628
Comments
@nihaux Bundling |
hello @oliviertassinari so I put up a minimal demo to reproduce. https://github.com/nihaux/demo-double-bundle-withstyles
I put the faulty conf in the rollup config I published it on npm. I also commited the dist for the demo purpose. Then this repo use it: I used the AppBar demo from the doc to show the css problem.
Everything works great when you're in dev mode but when you build the project and serve it (using https://github.com/zeit/serve) you'll see all the css bugging as soon as the faulty comp is loaded. |
pushed a non uglified/minified etc version of the build to make it easier to read |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@nihaux The reproduction example is perfect. Thanks. Let's see how we can improve the warnings. |
Also, I'm gonna add a not in the frequently asked question. People have been facing this issue for months: #8223 (comment) |
You should have a warning in the console next time. |
I have this exact issue, but I use webpack. All my libs must not package with the material-ui libs, but the main app, which imports the libs, should have it bundled right? |
I have the same Issue, does some1 have a solution that does not involve uncommenting code from material-ui? |
Ohai If anybody is still looking for a solution with webpack (for us it was an ejected create-react-app with material-ui elements, shared as a library, and then used in a similar cra app with material elements): https://webpack.js.org/guides/author-libraries/#external-limitations
Of course this means you want to indicate in your /build/package json that these are peerDependecies. You have to have them in the app where you wish to use this lib. |
Where exactly in the rollup.config.js should we put that ? please show a sample. |
This fix worked for me -- I'm surprised I haven't seen more people commenting! Thanks! |
So I spend the all afternoon reading the related issues and debugging my code so I am posting this here in case it helps someone.
I can make a PR for the doc if you want but don't know where it should go as it is not directly a MUI issue.
Use case:
external: [ 'react', '@material-ui/core', '@material-ui/icons', 'react-dom' ],
WRONG ! ;p
If you do this, you'll end up having jss classname conflicts in the production build of you final app.
why ?
cause
@material-ui/core
does not avoid@material-ui/core/List
for instance to be included in your dist package.and
@material-ui/core/List
will includewithStyles
which will cause jss class naming conflict in your final package !So the solution is, you should put this in your rollup config:
external: id => /react|react-dom|material-ui\/.*/.test(id),
this way all material-ui components will be excluded from your build... lost some hair with this one :p .
The text was updated successfully, but these errors were encountered: