1
votes

When I try to import Autocomplete exactly from the documentation: https://material-ui.com/components/autocomplete/ i get the following error message:

Failed to compile.

./node_modules/@material-ui/lab/esm/useAutocomplete/useAutocomplete.js
Attempted import error: 'unstable_useId' is not exported from '@material-ui/core/utils' (imported as 'useId').

react code:

/* eslint-disable no-use-before-define */
import React from 'react';
import TextField from '@material-ui/core/TextField';
import Autocomplete from '@material-ui/lab/Autocomplete';

export const MyTeamShiftPlanInput = () => {
  return (
    <Autocomplete
      id="combo-box-demo"
      options={top100Films}
      getOptionLabel={(option) => option.title}
      style={{ width: 300 }}
      renderInput={(params) => <TextField {...params} label="Combo box" variant="outlined" />}
    />
  );
}

// Top 100 films as rated by IMDb users. http://www.imdb.com/chart/top
const top100Films = [
  { title: 'The Shawshank Redemption', year: 1994 },
  { title: 'The Godfather', year: 1972 },
  { title: 'The Godfather: Part II', year: 1974 },
  { title: 'The Dark Knight', year: 2008 },
  { title: '12 Angry Men', year: 1957 },
  { title: "Schindler's List", year: 1993 },
  { title: 'Pulp Fiction', year: 1994 },
  { title: 'The Lord of the Rings: The Return of the King', year: 2003 },
  { title: 'The Good, the Bad and the Ugly', year: 1966 },
  { title: 'Fight Club', year: 1999 }
];

current versions of MUI:

    "@material-ui/core": "^4.9.10",
    "@material-ui/lab": "^4.0.0-alpha.49",
    "@material-ui/pickers": "^3.2.10",
2
I suggest you delete node_modules folder and install everything from beginning. Everything seems to be ok with your code. - Lazar Nikolic
This seems to be 'wrong peer dependency' issue with latest MUI version as per their github discussions forum. Try using 4.8 instead. - wr93_
thanks, @LazarNikolic. This worked perfectly! I feel kinda stupid now for wasting 1.5 hours on troubleshooting this. - Etika49
@WageeshaR i also read that but after reinstalling everything works great. - Etika49

2 Answers

2
votes

Its kind of bug on current tags so far, you could try to change your @material-ui/lab module's version

From:

"@material-ui/lab": "^4.0.0-alpha.49"

To:

"@material-ui/lab": "4.0.0-alpha.46"
0
votes

This is in addition to @Dhika's answer above.

His solution didn't work the first time I tried because I failed to notice there is no caret symbol in front of the version '"4.0.0-alpha.46"'.

To fix the issue

  1. run rm -rf node_modules/ to remove the node_modules folder
  2. open package.json and look for "@material-ui/lab": "^4.0.0-alpha.XX"
  3. modify the current version to "@material-ui/lab": "4.0.0-alpha.46"
  4. run npm install
  5. run npm start