1

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",
4
  • 1
    I suggest you delete node_modules folder and install everything from beginning. Everything seems to be ok with your code. Commented Apr 14, 2020 at 12:47
  • This seems to be 'wrong peer dependency' issue with latest MUI version as per their github discussions forum. Try using 4.8 instead. Commented Apr 14, 2020 at 12:55
  • thanks, @LazarNikolic. This worked perfectly! I feel kinda stupid now for wasting 1.5 hours on troubleshooting this. Commented Apr 14, 2020 at 12:57
  • @WageeshaR i also read that but after reinstalling everything works great. Commented Apr 14, 2020 at 12:58

2 Answers 2

2

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"
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, it solved my issue. To others encountering the same issue, take note that there's no caret (^) character in front of "4.0.0-alpha.46"
0

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

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.