question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Warning: Several instances of @material-ui/styles initialized

See original GitHub issue

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:

  • name: card
  • bundler: TypeScript
  • peerDependencies:
    • "@material-ui/styles": "^4.0.0-beta.2"

App:

  • bundler: Parcel
  • dependencies:
    • "@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 the index option in the makeStyles 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?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:22 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
lukejagodzinskicommented, May 19, 2019

Actually I solved my problem but it was related to adding package as dependency using the file protocol. It appears that it’s not behaving the same way as it would when package is published to the npm repository. It’s just symlink, so when you have some packages being installed in the node_modules it will count them too. I’ve just had to remove node_modules and make sure that yarn install does not put peer packages in the node_modules. Probably previously I was adding packages as regular dependency and later just changed it to peer dependency and package was not removed from the node_modules

2reactions
yuki-yoshimuracommented, Mar 14, 2020

In my case I was writing something like this inside my index.html file. <script src="/bundle.js"></script>

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. Bad me

Read more comments on GitHub >

github_iconTop Results From Across the Web

Warning: Several instances of @material-ui/styles initialized ...
Hey, I'm creating an app that imports my custom NPM package. Here is reproduction repository: ...
Read more >
Material UI styles not working in component (warning
It looks like there are several instances of `@material-ui/styles` initialized in this application. This may cause theme propagation issues, ...
Read more >
Frequently Asked Questions - Material UI - MUI
It looks like there are several instances of @mui/styles initialized in this application. This may cause theme propagation issues, broken class names, ...
Read more >
Perspective - several instances of `@material-ui/styles` - Ignition
SessionProps - It looks like there are several instances of `@material-ui/styles` initialized in this application. This may cause theme ...
Read more >
Material Ui Styles Not Working In Component (Warning
It looks like there are several instances of 'styled-components' initialized in this application. dynamic styles not rendering properly, missing elements, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found