Material UI: TypeError: Cannot read properties of undefined (reading 'up')

Viewed 628

I have this component and I'm trying to use "breakpoint", but I get this error, Note that I am using the latest version of the material:

Property 'breakpoints' does not exist on type 'DefaultTheme'

file.tsx:

import { Grid } from "@mui/material";
import { makeStyles } from '@mui/styles';
import { FC } from "react";
import ResponsiveConstants from "./ResponsiveConstants";

const useStyles = makeStyles((theme) => ({
  root: {
    [theme.breakpoints.up(ResponsiveConstants.mobileBreakpoint)]: {
      minHeight: 600,
    },
  },
}));

const ResponsiveContainerGrid: FC = ({  children }) => {
  const classes = useStyles();

  return (
    <div>
      <Grid
        className={classes.root}
        container
        direction="row"
        justifyContent="center"
        alignItems="center"
      >
        {children}
      </Grid>
    </div>
  );
};

export default ResponsiveContainerGrid;

Then I tried to modify the code and used the following instruction:

import { Theme } from '@mui/system';

And the code became:

import { Grid } from "@mui/material";
import { makeStyles } from '@mui/styles';
import { FC } from "react";
import ResponsiveConstants from "./ResponsiveConstants";
import { Theme } from '@mui/system';

const useStyles = makeStyles((theme: Theme) => ({
  root: {
    [theme.breakpoints.up(ResponsiveConstants.mobileBreakpoint)]: {
      minHeight: 600,
    },
  },
}));

const ResponsiveContainerGrid: FC = ({  children }) => {
  const classes = useStyles();

  return (
    <div>
      <Grid
        className={classes.root}
        container
        direction="row"
        justifyContent="center"
        alignItems="center"
      >
        {children}
      </Grid>
    </div>
  );
};

export default ResponsiveContainerGrid;

But I had a problem, which is:

TypeError: Cannot read properties of undefined (reading 'up')

How can I solve the first or second problem?

1 Answers

Delete the node_modules folder, then clear the NPM and/or Yarn cache by running:

  1. For NPM do: npm cache clean --force
  2. For Yarn do: yarn cache clean --force
  3. Next, reinstall all your packages with either npm or yarn. This resolved my problem
Related