material-ui: Using a styled(Grid) results in an error from 'RegularBreakpoints'

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/**/*"]
}

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 4
  • Comments: 15 (9 by maintainers)

Commits related to this issue

Most upvoted comments

@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

I’ve created a PR for it - #33751

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.

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.

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