Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Material UI React - Module not found: Can't resolve '@material-ui/pickers'

I got the following error:

Material UI React - Module not found: Can't resolve '@material-ui/pickers' in React.

I had the same message about '@date-io/date-fns' but managed to resolve it by updating to the newest version: npm i --save date-fns@next @date-io/date-fns

I suspect that it may need a similar solution.

The code is taken from the example on Material-UI website.

Thanks! Daniel

[import 'date-fns';
import React from 'react';
import Grid from '@material-ui/core/Grid';
import DateFnsUtils from '@date-io/date-fns';
import { MuiPickersUtilsProvider, KeyboardTimePicker, KeyboardDatePicker } from '@material-ui/pickers';

function MaterialUITest() {
  // The first commit of Material-UI
  const \[selectedDate, setSelectedDate\] = React.useState(new Date('2014-08-18T21:11:54'));

  const handleDateChange = (date) => {
    setSelectedDate(date);
  };

  return (
    <MuiPickersUtilsProvider utils={DateFnsUtils}>
      <Grid container justify="space-around">
        <KeyboardDatePicker
          disableToolbar
          variant="inline"
          format="MM/dd/yyyy"
          margin="normal"
          id="date-picker-inline"
          label="Date picker inline"
          value={selectedDate}
          onChange={handleDateChange}
          KeyboardButtonProps={{
            'aria-label': 'change date',
          }}
        />
        <KeyboardDatePicker
          margin="normal"
          id="date-picker-dialog"
          label="Date picker dialog"
          format="MM/dd/yyyy"
          value={selectedDate}
          onChange={handleDateChange}
          KeyboardButtonProps={{
            'aria-label': 'change date',
          }}
        />
        <KeyboardTimePicker
          margin="normal"
          id="time-picker"
          label="Time picker"
          value={selectedDate}
          onChange={handleDateChange}
          KeyboardButtonProps={{
            'aria-label': 'change time',
          }}
        />
      </Grid>
    </MuiPickersUtilsProvider>
  );
}

export default MaterialUITest;
like image 498
Daniel Janowski Avatar asked Jul 09 '20 12:07

Daniel Janowski


People also ask

How do you use makeStyles in material UI?

In order to use makeStyles function in your application you will need to import it in the component in where you plan to access the css that results from your makeStyles function. This is assuming you have already installed Material Ui in your project. This is in order for react to recognize it as a styles file.

Does material UI support React 18?

@mui/styles v5 is not compatible with React 18 · Issue #32142 · mui/material-ui · GitHub.


1 Answers

You need to install that dependency as the following:

npm install @material-ui/pickers

After it can be resolved, this helped the problem on my end.

like image 130
norbitrial Avatar answered Oct 26 '22 00:10

norbitrial