Can't resolve '@material-ui/lab/Slider' in {path}

Viewed 30858

I imported the Slider:

import Slider from '@material-ui/lab/Slider';

and have returned in the render.

The code is not getting compiled and is throwing an error:

Module not found: Error: Can't resolve '@material-ui/lab/Slider' in {path}.

Could anyone help me with this? Thanks.

9 Answers

You have to install the lab package: npm install @material-ui/lab

Updated answer as of February 2021: Slider has been moved into core, so you should change your import to:

import Slider from '@material-ui/core/Slider';

Run the following command in the your terminal/ cmd :

npm install @material-ui/lab

After successful installation, restart the server. It will work properly. You can check manually in your node_modules/@material-ui. You will find lab folder in it.

Error itself shout a lot.

Module not found

That means you've to install the module if its not part of your project.

lab doesn't come with material/core

Just install the lab package through any package manager NPM or YARN

npm

npm install @material-ui/lab

yarn

yarn add @material-ui/lab

I would suggest to use only one package at a time, And also check if the lock file exist. Sometimes it conflicts and cause issue with the existing packages.

The solution that worked for me is the followin (use --save to save the dependencency in package.jso)

 npm install @material-ui/lab --save

I faced the same problem with Pagination from @material-ui/lab/Pagination and faced the same error because I just installed @material-ui/lab with version 4.0.0-alpha.57 but I was using old version of @material-ui/core which was below 4.0.

I uninstalled @material-ui/core and re-installed npm package and it solved the issue.

I was able to resolve the issue after installing @mui/lab package with material ui 5.0.4.

For yarn users: yarn add @mui/lab

For npm users: npm install @mui/lab

Try to install both @material-ui/lab and @material-ui/core.

npm install @material-ui/lab
npm install @material-ui/core

The above tested for @material-ui/core v4.12 and @material-ui/lab v4.0.

You might also need MUI icons package installed (npm install @mui/material @emotion/react @emotion/styled): https://stackoverflow.com/a/71806305

Related