31

Can't resolve '@material-ui/lab/AdapterDateFns'

Can't resolve '@material-ui/lab/DateTimePicker'

Can't resolve '@material-ui/lab/LocalizationProvider'

I am getting these errors even after having installed @material-ui/lab

2
  • 1
    Do npm install @material-ui/lab
    – Shivam Jha
    Feb 9, 2021 at 4:49
  • I have the same problem. even after hitting 'npm install @material-ui/lab' and 'npm install @mui/lab' the problem still exists. anyone willing to help? Apr 18, 2022 at 8:46

6 Answers 6

16

This works for me very well

npm install @mui/lab

In Material UI v5 you need to install @mui/lab.My dependencies are here :

  "dependencies": {
    "@mui/lab": "^5.0.0-alpha.54",
    "@mui/material": "^5.2.1",
  }

For more information check this link

2
  • 2
    While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value. You can find more information on how to write good answers in the help center: stackoverflow.com/help/how-to-answer . Good luck 🙂
    – nima
    Nov 2, 2021 at 15:12
  • 2
    What is exact requirement? I have "@mui/lab": "^5.0.0-alpha.73", "@mui/material": "^5.4.4", "date-fns": "^2.28.0" in my package.json, still I get this error.
    – MsA
    Mar 18, 2022 at 22:24
12

I have a working codesandbox here: https://codesandbox.io/s/youthful-wave-8xjy4

Make sure both @material-ui/core and @material-ui/lab are at version "5.0.0-alpha.24" or above as I ran into the same import errors as you when following the guide at: https://next.material-ui.com/guides/pickers-migration/

// package.json
{
  "dependencies": {
    "@emotion/react": "11.1.5",
    "@emotion/styled": "11.1.5",
    "@material-ui/core": "5.0.0-alpha.24",
    "@material-ui/lab": "5.0.0-alpha.24",
    "date-fns": "2.17.0",
    "react": "17.0.1",
    "react-dom": "17.0.1",
    "react-scripts": "4.0.0"
  },
}
1
  • What is exact requirement? I have "@mui/lab": "^5.0.0-alpha.73", "@mui/material": "^5.4.4", "date-fns": "^2.28.0" in my package.json, still I get this error.
    – MsA
    Mar 18, 2022 at 22:23
6

Try running npm install @material-ui/core@next and npm install @material-ui/lab@next

This should move you to version 5.

If the need arises, delete the node_modules folder and run npm install.

Now if you look into the lab folder in node_modules/@material-ui, you will see the

0
1

Make sure that you installed a date management library. I think that @material-ui/lab/AdapterDateFns will be supported with the date-fns library.

date-fns installation

I read it at mui documentation for React Date Picker.

1

For date pickers in React MUI install the below two:

  • @mui/x-date-pickers for the free community version.
  • The date library to manipulate the date.
npm install @mui/x-date-pickers
    
// Install date library (if not already installed)
npm install dayjs

For rendering the date picker:

import * as React from 'react';
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
import { DatePicker } from '@mui/x-date-pickers/DatePicker';

export default function FirstComponent() {
  return (
    <LocalizationProvider dateAdapter={AdapterDayjs}>
      <DatePicker />
    </LocalizationProvider>
  );
}

For more details, read this link.

0

THIS WORKED FOR ME!!!! I went into the node_modules to look for the specific files:

  1. The location of the imports was not accurate so I changed them accordingly
  2. Then all these components are exported as a default so I removed the curly braces and it worked for me.

I have installed these :

    "@emotion/react": "^11.10.5",
    "@emotion/styled": "^11.10.5",
    "@mui/lab": "^5.0.0-alpha.108",
    "@mui/material": "^5.10.14",

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.