Installing non-latest versions of @material-ui/core and @material-ui/styles results in 2 versions of @material-ui/styles #17418
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.
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 useinjectFirst
: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 aswithStyles
,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 🕹
yarn install
and start the app withyarn start
astorije/sort-of-fix
branch where the dependencies were updated to latest, restart the app, and see the red buttonContext 🔦
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 ofyarn.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.The text was updated successfully, but these errors were encountered: