-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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
Warning: Several instances of @material-ui/styles initialized #15745
Comments
I've also prepared version of this app that uses Webpack instead of Parcel and the same problem occurs. So it's nothing related with the bundler, or actually it might be a problem with all the bundlers. However, it's somehow solved for the React package in MaterialUI and it's also known that we can't have two different versions of React working in the same app. |
We have tried to provide as many information about the problem in https://next.material-ui.com/getting-started/faq/#duplicated-module-in-node-modules. I fear we can help more. Let us know when you find the solution, hopefully, it will help someone else! |
@oliviertassinari if you're gonna help me with this warning, then at least help me with the |
I'm sorry, I can't help you. |
👋 Thanks for using Material-UI! We use the issue tracker exclusively for bug reports and feature requests, however, If you would like to link from here to your question on SO, it will help others find it. |
We get this warning in our own docs. Not sure if there are too many false positives involved. |
@eps1lon Is it on the server side, between two HMR updates? |
Actually I solved my problem but it was related to adding package as dependency using the |
Yes. |
@lukejagodzinski , can you please elaborate on your solution? I do not quite follow your description and I'm having exactly the same issue (material-ui also listed as peer dependency in my npm package). |
@dkadrios to be honest it still is pain in the ass to deal with peer dependencies :) as new problems appeared. However, to answer your question. You have two directories, one with your application and the other one with the package. In the package you have In my case, in the package I also had the The other solution, I found recently that solves all the problems is using monorepo with Lerna and Yarn workspaces to just have all the dependencies installed only once at the top level. |
Thanks, @lukejagodzinski. Monorepo would certainly solve this. The trouble is the one npm package is public while the other repos are private and it feels like asking for trouble to get that working. Right now I'm trying to get it working using webpack resolve as described at https://material-ui.com/getting-started/faq/#duplicated-module-in-node-modules |
Hey, @lukejagodzinski , can you elaborate this part? I did what you said and yes, now |
@alexandrecanuto I've just used Babel to build package instead of TypeScript compiler. Take a look at this line: https://github.com/mui-org/material-ui/blob/master/packages/material-ui-styles/package.json#L31 |
@lukejagodzinski I think you tagged the wrong person 🙂 |
@aleccaputo oh right, sorry :D |
This is how i solved the problem for me, hope it helps.
Note that my yarn.lock file appeared to refer to multiple versions of @material-ui/styles. |
In my case I was writing something like this inside my index.html file. But I was also using HtmlWebpackPlugin (a plugin which automatically add bundle.js reference inside index.html) inside my webpack.config.js. So I just solved this by removing the bundle.js reference from index.html. |
It's the same for me! |
I'm having this issue as well. The Any ideas for fixing this issue when using |
Hey @oliviertassinari, once Webpack 5 allows ESM modules output, can you suggest if this double bundling concern will still remain? Edit: Ref: webpack/webpack#2933 |
Scenario: pnpm, CRA, Jest. The following worked for me. In primary App (not the external Storybook library):
|
Hey, I'm creating an app that imports my custom NPM package. Here is reproduction repository: https://github.com/lukejagodzinski/mui-styles-reproduction
Little bit info about package and app.
Package:
card
TypeScript
"@material-ui/styles": "^4.0.0-beta.2"
App:
Parcel
"@material-ui/styles": "^4.0.0-beta.2"
"card": "file:../card"
I'm using
Yarn
In the package I'm not bundling dependencies and they are peer dependencies so the app using a package can define it and that's what I'm doing. However, I still get error:
It looks like there are several instances of "@material-ui/styles" initialized in this application. This may cause theme propagation issues, broken class names and makes your application bigger without a good reason.
I've followed instructions but I can't solve this problem. It still loads
styles
package twice. It also problematic for me for another reason. I'm using theindex
option in themakeStyles
function, to force given order of the styles but having two packages makes it impossible to use the same order sequence in both package and app.Any ideas?
The text was updated successfully, but these errors were encountered: