【发布时间】:2020-07-27 04:40:10
【问题描述】:
当我尝试完全从文档中导入自动完成功能时: https://material-ui.com/components/autocomplete/ 我收到以下错误消息:
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').
反应代码:
/* 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 }
];
当前版本的 MUI:
"@material-ui/core": "^4.9.10",
"@material-ui/lab": "^4.0.0-alpha.49",
"@material-ui/pickers": "^3.2.10",
【问题讨论】:
-
我建议您删除 node_modules 文件夹并从头开始安装所有内容。您的代码似乎一切正常。
-
根据他们的 github 讨论论坛,这似乎是最新 MUI 版本的“错误对等依赖”问题。尝试改用 4.8。
-
谢谢,@LazarNikolic。这非常有效!我现在觉得浪费 1.5 小时来解决这个问题有点愚蠢。
-
@WageeshaR 我也读过,但重新安装后一切正常。
标签: reactjs input material-ui