React js Material UI Error export 'LocalizationProvider' (imported as 'LocalizationProvider') was not found in '@mui/lab/LocalizationProvider
Asked Answered
O

1

6

I am new to React Js Material Ui. I am using latest version of MUI. I already installed mui/lab. When I trying to use DatePicker component, it throws an error like this.

Here is my code.

import * as React from 'react';
    import AdapterDateFns from '@mui/lab/AdapterDateFns';
    import LocalizationProvider from '@mui/lab/LocalizationProvider';
    import DatePicker from '@mui/lab/DatePicker';
    
    function User() {
  const [joiningDate, handleJoiningDate] = useState(new Date());
  
   return (
    <LocalizationProvider dateAdapter={AdapterDateFns}>
      <DatePicker
        value={joiningDate} onChange={ handleJoiningDate }   
      />
    </LocalizationProvider>
  );
}

export default User;

When I save this code, I am getting error like this in my terminal.

export 'LocalizationProvider' (imported as 'LocalizationProvider') was not found in '@mui/lab/LocalizationProvider

https://mui.com/components/date-picker/#localization I tried using the above link. But I cant able to rectify why this error came!! Help me to came out of this error. Thanks in advance.

Operate answered 28/1, 2022 at 9:9 Comment(0)
G
0

I was faced with similar issue. I solved it by trying with one of the following imports:

import { LocalizationProvider } from '@mui/x-date-pickers-pro/LocalizationProvider';
// or
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
// or
import { LocalizationProvider } from '@mui/x-date-pickers-pro';
// or
import { LocalizationProvider } from '@mui/x-date-pickers';

In my case, the first one was not working, then I changed it by the second import and it worked perfectly.

Please, find here the official MUI docs

EDIT:

Make sure also that you already installed date picker dependency. Follow this link to see how to install it according to your need.

If you use the actual version of MUI, please note that the date picker is now moving from @mui/lab to @mui/x-date-pickers. You need to migrate. Please follow the official instruction here to do so.

Goldagoldarina answered 27/2, 2023 at 6:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.