8
votes

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;
1
there is an extra [ at the first line of your code - Joseph
There could be a situation where the unresolvable module of your's is not supporting your current version. I would recommend checking that. - BUY
That [ is not in original code. - Daniel Janowski

1 Answers

10
votes

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.