mui / material-ui

Material UI: Comprehensive React component library that implements Google's Material Design. Free forever.
https://mui.com/material-ui/
MIT License
93.99k stars 32.29k forks source link

[lab] Incomplete peerDependencies break usage with yarn pnp #32620

Closed nate-summercook closed 2 years ago

nate-summercook commented 2 years ago

Duplicates

Latest version

Current behavior 😯

Yarn PnP (Plug'n'Play) is more strict when it comes to specifying a library's peerDependencies correctly. Currently, @mui/lab is missing the following entries in peerDependencies as they are peerDependencies of @mui/x-date-pickers:

This causes errors like this one:

ERROR in resolving fallback for shared module @emotion/styled
Module not found: Error: @mui/styled-engine tried to access @emotion/styled (a peer dependency) but it isn't provided by its ancestors; this makes the require call ambiguous and unsound.

Required package: @emotion/styled
Required by: @mui/styled-engine@virtual:7a413bb353e548319c90adb82631b0c089acd1a802fdcf34c7a70f0d92986c9f29874633545bb7dc3d02df8b9ae9870617074e94e1a662f0e58596867aac2836#npm:5.6.1 (via /workspace-root/.yarn/__virtual__/@mui-styled-engine-virtual-d4f5f5ea46/0/cache/@mui-styled-engine-npm-5.6.1-06c551ec66-cd17d05902.zip/node_modules/@mui/styled-engine/)

Ancestor breaking the chain: @mui/lab@virtual:be640854c908ca72c5c45d17e3a5d76a2c579538ed551547b39edc486c90638abf94c25a34fa05a0a9167f796b8fb98e280e0bad9b44c61172fe75f4bcf39869#npm:5.0.0-alpha.80

Expected behavior 🤔

If the mentioned packages were added to peerDependencies, these errors would not occur with yarn pnp.

It would maybe also make sense to add them as optional peer dependencies because mui can also be used with styled-components instead of emotion.

Steps to reproduce 🕹

This bug is connected to https://github.com/mui/mui-x/issues/4761. I created a PR to fix the issue on @mui/x-date-pickers but after that, this library depending on @mui/x-date-pickers will have the same problem as it also doesn't declare these peer deps. So reproduction for this issue would be the same (also after mui-x is fixed):

  1. Set up a new react app (i.e. via CRA) npx create-react-app mui-x-date-pickers
  2. Make sure you have yarn installed
  3. run yarn set version berry in order to get the latest yarn version with pnp
  4. run yarn add @mui/lab @mui/material @mui/system
  5. Implement usage of one of these date pickers:
    
    import {CalendarPicker} from '@mui/lab';

function App() { const handleDateChange = () => { };

return ( <CalendarPicker date={null} onChange={handleDateChange} /> ); }

export default App;

6. start the app --> errors appear.

### Context 🔦

I'm in an environment where I rely heavily upon yarn functionalities (yarn workspaces, pnp, etc.). This issue is a major blocker for me.

### Your environment 🌎

<details>
  <summary>`npx @mui/envinfo`</summary>

System: OS: macOS 12.3.1 Binaries: Node: 16.11.1 - /opt/javascript/ncanode/16.11.1/node/bin/node Yarn: 3.2.0 - /opt/javascript/ncayarn/1.22.4/bin/yarn npm: 8.0.0 - /opt/javascript/ncanode/16.11.1/node/bin/npm Browsers: Chrome: 101.0.4951.54 Edge: Not Found Firefox: 99.0.1 Safari: 15.4 Browser used: Brave [Version 1.37.116 Chromium: 100.0.4896.127 (Official Build)]


</details>
alippai commented 2 years ago

@oliviertassinari @nate-summercook maybe it's caused by the -alpha.0 dependency (instead of -alpha.2) here: https://github.com/mui/material-ui/blob/master/packages/mui-lab/package.json#L75

If you are on react v18 the current versions are unresolvable (as -alpha.0 had only react v17 peer dependency)

nate-summercook commented 2 years ago

@oliviertassinari @nate-summercook maybe it's caused by the -alpha.0 dependency (instead of -alpha.2) here: https://github.com/mui/material-ui/blob/master/packages/mui-lab/package.json#L75

No, I did try with -alpha.2 (through resolutions. Didn't fix the problem.

oliviertassinari commented 2 years ago

@nate-summercook Please provide a minimal reproduction. @mui/x-date-pickers is not supposed to be used though @mui/lab for new projects. In step 4, you also need to install @emotion/react and @emotion/styled in your project.

github-actions[bot] commented 2 years ago

Since the issue is missing key information, and has been inactive for 7 days, it has been automatically closed. If you wish to see the issue reopened, please provide the missing information.

nate-summercook commented 2 years ago

@nate-summercook Please provide a minimal reproduction. @mui/x-date-pickers is not supposed to be used though @mui/lab for new projects. In step 4, you also need to install @emotion/react and @emotion/styled in your project.

I'm not using @mui/x-date-pickers through @mui/lab, but the fact that it's contained within @mui/lab lets yarn pnp fail already because the peerDependencies are not declared.