Skip to content
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

Installing non-latest versions of @material-ui/core and @material-ui/styles results in 2 versions of @material-ui/styles #17418

Closed
2 tasks done
astorije opened this issue Sep 13, 2019 · 0 comments · Fixed by #17419
Labels
core Infrastructure work going on behind the scenes package: styles Specific to @mui/styles. Legacy package, @material-ui/styled-engine is taking over in v5.

Comments

@astorije
Copy link

When installing the non-latest version of @material-ui/core and @material-ui/styles, 2 copies of @material-ui/styles get used at runtime, which causes the following warning and prevents us to use injectFirst:

Screen Shot 2019-09-13 at 1 47 02 PM

  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

For the sake of argument, let's assume that the latest releases of @material-ui/core and @material-ui/styles are both v4.4.1.
Installing older versions such as yarn add @material-ui/[email protected] @material-ui/[email protected] actually installs both v4.3.3 and v4.4.1 of @material/styles: v4.3.3 is the version explicitly requested, and v4.4.1 is the version that gets installed via @material-ui/core (as it satisfies ^4.3.3`).

Expected Behavior 🤔

Installing non-latest versions should not ship both versions of @material-ui/styles.

I know that this can be resolved by tweaking the Webpack configuration to tell it to load the correct version, but we would prefer to actually fix this issue.
Solutions I can think of:

  • Export StylesProvider from @material-ui/core. This is the only reason why we have @material-ui/styles as a dependency, we import other style-related references from @material-ui/core/styles (such as withStyles, MuiThemeProvider, createMuiTheme, etc.). This would be our preferred solution (unless it's already importable from @material-ui/core and I missed it somehow).

  • Make @material-ui/styles a peer dependency of @material-ui/core instead of a regular dependency, so that one and only one version gets installed by consumers.

Steps to Reproduce 🕹

  1. Clone https://github.com/astorije/repro-material-issue
  2. Install dependencies with yarn install and start the app with yarn start
  3. Go to http://localhost:8080 and notice: 1) the warning in the JS console, 2) the button is not red
  4. Switch to the astorije/sort-of-fix branch where the dependencies were updated to latest, restart the app, and see the red button

Context 🔦

We develop a shared component library on top of Material UI, that then gets consumed by many applications. We are not always up to date on dependencies, which is when this issue happens.
We could probably solve this by manually editing the yarn.lock file to consolidate these, but new applications get spun up by a mainly-autonomous script that installs dependencies and prepares projects, so scripting edits of yarn.lock could get really messy.

Your Environment 🌎

All dependency versions can be found in the package.json file though the versions themselves do not matter: as long as you are trying to install non-latest versions of Material UI, you will run into this issue.

@oliviertassinari oliviertassinari added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Dec 20, 2022
@zannager zannager added package: styles Specific to @mui/styles. Legacy package, @material-ui/styled-engine is taking over in v5. core Infrastructure work going on behind the scenes labels Dec 20, 2022
@zannager zannager removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Jan 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Infrastructure work going on behind the scenes package: styles Specific to @mui/styles. Legacy package, @material-ui/styled-engine is taking over in v5.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants