Reactjs 物料UI输入自动完成在React.js中不起作用
当我尝试完全从文档导入Autocomplete时: 我收到以下错误消息:Reactjs 物料UI输入自动完成在React.js中不起作用,reactjs,input,material-ui,Reactjs,Input,Material Ui,当我尝试完全从文档导入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'). 反应代码: /*
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 }
];
到目前为止,它是当前标签上的一种缺陷,您可以尝试更改@material ui/lab模块的版本 发件人:
"@material-ui/lab": "^4.0.0-alpha.49"
致:
这是对以上@Dhika答案的补充 我第一次尝试时,他的解决方案不起作用,因为我没有注意到版本
“4.0.0-alpha.46”
前面没有插入符号
解决问题
rm-rf node_modules/
删除node_modules文件夹package.json
并查找“@material ui/lab”:“^4.0.0-alpha.XX”
“@material ui/lab”:“4.0.0-alpha.46”
npm安装
npm启动
我建议您删除node_modules文件夹并从一开始安装所有内容。您的代码似乎一切正常。根据github讨论论坛,最新MUI版本似乎存在“错误的对等依赖”问题。试着用4.8代替。谢谢,@LazarNikolic。这工作做得很好!我现在觉得有点傻,浪费了1.5个小时来解决这个问题。@Wageshar我也读过,但在重新安装后一切都很好。谢谢,它解决了我的问题。对于遇到相同问题的其他人,请注意“4.0.0-alpha.46”前面没有插入符号(^)字符
"@material-ui/lab": "^4.0.0-alpha.49"
"@material-ui/lab": "4.0.0-alpha.46"