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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using a styled(Grid) results in an error from 'RegularBreakpoints' #33165

Closed
2 tasks done
achendrick opened this issue Jun 15, 2022 · 15 comments 路 Fixed by #33751
Closed
2 tasks done

Using a styled(Grid) results in an error from 'RegularBreakpoints' #33165

achendrick opened this issue Jun 15, 2022 · 15 comments 路 Fixed by #33751
Assignees
Labels
bug 馃悰 Something doesn't work component: Grid The React component. typescript

Comments

@achendrick
Copy link

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior 馃槸

import { styled, Grid } from '@mui/material';

export const StyledGrid = styled(Grid)(({ theme }) => ({}));

Doing the above is resulting in the following error
Exported variable 'StyledGrid' has or is using name 'RegularBreakpoints' from external module "{project_path}/node_modules/@mui/material/Grid/Grid" but cannot be named.

Expected behavior 馃

If I export RegularBreakpoints the error goes away so I'd expect that or a similar solution.

Steps to reproduce 馃暪

Steps:

  1. Create a project with 5.8.4 of @mui/material
  2. Create a file in the project that has the following code:
import { styled, Grid } from '@mui/material';

export const StyledGrid = styled(Grid)(({ theme }) => ({}));

Context 馃敠

No response

Your environment 馃寧

.tsconfig

{
  "compilerOptions": {
    "target": "ES2015",
    "outDir": "./dist/esm/",
    "strictNullChecks": true,
    "moduleResolution": "node",
    "allowJs": true,
    "strict": true,
    "esModuleInterop": true,
    "jsx": "react",
    "baseUrl": "./src",
    "lib": ["es2015", "dom.iterable", "es2016.array.include", "es2017.object", "dom", "esnext"],
    "module": "ESNext",
    "removeComments": true,
    "alwaysStrict": true,
    "allowUnreachableCode": false,
    "noImplicitAny": true,
    "noImplicitThis": true,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,
    "forceConsistentCasingInFileNames": true,
    "importHelpers": true,
    "sourceMap": true,
    "declaration": true,
    "declarationDir": "./dist/typings/",
    "downlevelIteration": true,
    "typeRoots": ["./src/typings", "./node_modules/@types", "../../node_modules/@types"],
    "types": ["jest", "node"],
    "skipLibCheck": true
  },
  "files": ["./src/index.tsx"],
  "include": ["./src/**/*"]
}
@achendrick achendrick added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Jun 15, 2022
@rejetto
Copy link
Contributor

rejetto commented Jun 16, 2022

I can confirm this (recent) problem. For the moment I'm workarounding it by forcing the type as ReactElement.

@achendrick
Copy link
Author

@rejetto good idea 馃憤馃徎, much better than just reverting to 5.8.3

I ended up going with export const StyledGrid = styled(Grid)(({ theme }) => ({})) as typeof Grid; which worked a little better for me.

rejetto added a commit to rejetto/hfs that referenced this issue Jun 19, 2022
@mnajdova mnajdova self-assigned this Jun 20, 2022
@mnajdova

This comment was marked as outdated.

@mnajdova mnajdova added bug 馃悰 Something doesn't work good first issue Great for first contributions. Enable to learn the contribution process. component: Grid The React component. typescript and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Jun 20, 2022
@jooohyun
Copy link

Hmmm... I have created react project using vite.js (NOT create-react-app).
and I write the below code

import { styled, Grid } from '@mui/material';

export const StyledGrid = styled(Grid)(({ theme }) => ({}));

BUT, there are no error.

@mnajdova
Copy link
Member

@mnajdova mnajdova added status: waiting for author Issue with insufficient information and removed good first issue Great for first contributions. Enable to learn the contribution process. labels Jun 20, 2022
@rejetto
Copy link
Contributor

rejetto commented Jun 20, 2022

I'm using CRA

@mnajdova
Copy link
Member

@rejetto please share a codesandbox with a reproduction

@jooohyun
Copy link

https://codesandbox.io/s/kind-chatterjee-7bwd6w?file=/src/index.tsx

this is CRA(typescript) project. as you can see there are no errors.

@rejetto
Copy link
Contributor

rejetto commented Jun 20, 2022

Sorry, I didn't notice I've been quite inaccurate.
My use case is a monorepo, containing a CRA app, but the problem is inside a lib that's actually built simply by tsc.

So this is where I hade to force the type
https://github.com/rejetto/hfs/blob/208df4891044728fa4de94e05492fe996227135e/mui-grid-form/src/StringStringField.ts#L93

And these are related configurations
https://github.com/rejetto/hfs/blob/main/mui-grid-form/package.json
https://github.com/rejetto/hfs/blob/main/mui-grid-form/tsconfig.json

Version of mui is actually found here, which I just checked it is 5.8.4

I'm sorry I'm not providing better information, but it may take long before I find the necessary time.
Any help is appreciated, nothing expected, and I can actually live with my workaround.
Thanks for all the rest, by the way

@mnajdova
Copy link
Member

Sorry, but this is not enough info for us to look into. Please re-open the issue when there is a reproduction that we can look into.

@rejetto
Copy link
Contributor

rejetto commented Jun 21, 2022

Sure!

I discovered the error disappears on my side when I disable declaration in my tsconfig.json.
This way I was able to give you this: https://codesandbox.io/s/dry-shadow-x950wv?file=/src/App.tsx
I just modified tsconfig.
It may take a while before the problem appears, so I'm adding also a screenshot (from codesandbox), just in case
image

Typescript needs the exported type to generate a valid .d.ts .
This makes me think the problem doesn't apply to building apps (generates js only), while applies to building libraries (js + d.ts).
Anyway, disabling declaration files doesn't seem to be an option for libraries.

At this very moment I ran out of time (rushing to work), and cannot proceed testing your proposed solution, but it seems fine to me.

@achendrick
Copy link
Author

@rejetto is exactly right. You will not see this error if you don't also update your tsconfig.json to have "declaration": true

All that would need to be done to address this issue would be export interface RegularBreakpoints

@github-actions github-actions bot removed the status: waiting for author Issue with insufficient information label Jun 21, 2022
@github-actions github-actions bot reopened this Jun 21, 2022
@John-Dennehy
Copy link

Having the same issue in a UI package in a monorepo.

@r-hede
Copy link

r-hede commented Jul 20, 2022

@achendrick is exactly right!

All that needs to be done to fix this is to export the RegularBreakpoints interface.

https://github.com/mui/material-ui/blob/master/packages/mui-material/src/Grid/Grid.d.ts#L22

@ZeeshanTamboli
Copy link
Member

I've created a PR for it - #33751

@ZeeshanTamboli ZeeshanTamboli self-assigned this Aug 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 馃悰 Something doesn't work component: Grid The React component. typescript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants