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.85k stars 32.25k forks source link

Error in @mui/system: Modules `./typography` and others have no exported member `default` #43685

Closed morozow closed 1 month ago

morozow commented 1 month ago

Steps to reproduce

Link to live example: local dev as there's no TS completion to build live phase

Description:

  1. When attempting to build a TypeScript project that imports from @mui/system, the TypeScript compiler throws the following error:
    
    node_modules/@mui/system/typography/index.d.ts:1:10 - error TS2305: Module '"./typography"' has no exported member 'default'.

1 export { default } from './typography';


Steps to Reproduce
1. Install the latest version of `@mui/system` via yarn or follow a [Default Installation - Material UI](https://mui.com/material-ui/getting-started/installation/#default-installation)
2. Set up a TypeScript project that imports `@mui/system`.
3. Run the TypeScript compiler.

The same issue with: 
- Module `./borders`...
- Module `./cssGrid`...
- Module `./display`...
- Module `./flexbox`...
- Module `./palette`...
- Module `./positions`...
- Module `./shadows`...
- Module `./sizing`...
- Module `./spacing`...
- Module `./style`...
- Module `./typography`...

### Current behavior

The TypeScript compiler fails with a TS2305 error indicating that `index.d.ts` incorrectly attempts to export a non-existent `default` member from `./typography`.

error TS2305: Module '"./typography"' has no exported member 'default'.

1 export { default } from './typography';


### Expected behavior

The TypeScript compiler should complete without errors, allowing for the proper usage of the `@mui/system` package components.

### Context

**Additional Context**
- Node.js version: v20.9.0
- yarn version: 1.22.19
- TypeScript version: 5.6.2
- MUI System version: 6.0.2

### Your environment

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

System: OS: macOS 14.1.1 Binaries: Node: 20.9.0 - /usr/local/bin/node npm: 10.2.4 - /usr/local/bin/npm pnpm: Not Found Browsers: Chrome: 128.0.6613.120 Edge: Not Found Safari: 17.1 npmPackages: @emotion/react: ^11.13.3 => 11.13.3 @emotion/styled: ^11.13.0 => 11.13.0 @mui/core-downloads-tracker: 6.0.2 @mui/envinfo: ^2.0.25 => 2.0.25 @mui/icons-material: ^6.0.2 => 6.0.2 @mui/material: ^6.0.2 => 6.0.2 @mui/private-theming: 6.0.2 @mui/styled-engine: 6.0.2 @mui/styles: ^6.0.2 => 6.0.2 @mui/system: 6.0.2 @mui/types: 7.2.16 @mui/utils: 6.0.2 @mui/x-date-pickers: ^7.16.0 => 7.16.0 @mui/x-internals: 7.16.0 @types/react: ^18.3.5 => 18.3.5 react: ^18.3.1 => 18.3.1 react-dom: ^18.3.1 => 18.3.1 typescript: ^5.6.2 => 5.6.2


</details>

**Search keywords**: error, types, d.ts
morozow commented 1 month ago

Nitpick: If anyone encounters this issue, here is a quick fix for Unix systems using Yarn post-install:

#!/bin/bash
cd ./

find . -type f -name "*.d.ts" -exec sed -i'' -e 's#export = dayjs;*#export default dayjs;#g' {} +
find . -type f -name "index.d.ts" -exec sed -i'' -e '/export { default } from '\''\.\/borders'\'';/d' {} +
find . -type f -name "index.d.ts" -exec sed -i'' -e '/export { default } from '\''\.\/cssGrid'\'';/d' {} +
find . -type f -name "index.d.ts" -exec sed -i'' -e '/export { default } from '\''\.\/display'\'';/d' {} +
find . -type f -name "index.d.ts" -exec sed -i'' -e '/export { default } from '\''\.\/flexbox'\'';/d' {} +
find . -type f -name "index.d.ts" -exec sed -i'' -e '/export { default } from '\''\.\/palette'\'';/d' {} +
find . -type f -name "index.d.ts" -exec sed -i'' -e '/export { default } from '\''\.\/positions'\'';/d' {} +
find . -type f -name "index.d.ts" -exec sed -i'' -e '/export { default } from '\''\.\/sizing'\'';/d' {} +
find . -type f -name "index.d.ts" -exec sed -i'' -e '/export { default } from '\''\.\/spacing'\'';/d' {} +
find . -type f -name "index.d.ts" -exec sed -i'' -e '/export { default } from '\''\.\/style'\'';/d' {} +
find . -type f -name "index.d.ts" -exec sed -i'' -e '/export { default } from '\''\.\/typography'\'';/d' {} +
find . -type f -name "index.d.ts" -exec sed -i'' -e 's#export { default } from '\''\.\/shadows'\'';*#export * from '\''\.\/shadows'\'';#g' {} +

Smth like this into package.json:

...
"scripts": {
    "postinstall": "bash ./bin/post.install.sh",
}
...

That works also for a new age "@mui/x-date-pickers": "^7.16.0",

siriwatknp commented 1 month ago

Are you using @mui/system directly? Usually, @mui/system is not required to be installed explicitly if you use Material UI (it's already a dependency)

If you need more help, please provide a CodeSandbox or a repo that we can take a look.

morozow commented 1 month ago

No, I don’t directly use @mui/system. Upon reviewing my package.json, the only dependencies listed are "@mui/icons-material": "^6.0.2", "@mui/material": "^6.0.2", "@mui/styles": "^6.0.2", and "@mui/x-date-pickers": "^7.16.0", with "@mui/envinfo": "^2.0.25" included in devDependencies. It appears that @mui/envinfo aggregates all dependencies independently of package.json. Therefore, the foregoing solution is currently the only fix from my local perspective. Any suggestions? Following a GitHub implementation, it indeed looks like the default export is missing. What could be the reason for this export?

Details:

Comparison of suitable imports:

Nitpick: object type may not be the most suitable here. Consider using unknown or any other generic type that more accurately represents the value

morozow commented 1 month ago

Here are my 2 cents on automating deployment while the above issue remains unresolved: https://github.com/mui/material-ui/issues/43700#issuecomment-2342067775

morozow commented 1 month ago

This Pull Request eliminates undefined exports: https://github.com/mui/material-ui/pull/43702

Please review it and let me know if there are any additional contributions or changes needed.

Additional note: currently in dev phase as vita has an exception while built

morozow commented 1 month ago

The problem has been fixed by updating the documentation: https://github.com/mui/material-ui/pull/43747

github-actions[bot] commented 1 month ago

This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue. Now, if you have additional information related to this issue or things that could help future readers, feel free to leave a comment.

[!NOTE] We value your feedback @morozow! How was your experience with our support team? If you could spare a moment, we'd love to hear your thoughts in this brief Support Satisfaction survey. Your insights help us improve!