模块未找到:错误:无法解析'C:\ Users \ XXX'中的'date-fns / addDays'
模块未找到:错误:无法解析'C:\ Users \ XXX'中的'date-fns / addDays'
我想使用MUI的日期选择器,但是我得到了这个错误,我不知道到底出了什么问题。
这是我的代码:
import TextField from "@mui/material/TextField"; import DatePicker from "@mui/lab/DatePicker"; import AdapterDateFns from "@mui/lab/AdapterDateFns"; import LocalizationProvider from "@mui/lab/LocalizationProvider"; const ExpenseForm = () => { return (); }; export default ExpenseForm; {}} renderInput={(params) => } />
以及我的package.json文件:
"dependencies": {
"@date-io/date-fns": "^2.13.1",
"@emotion/react": "^11.7.1",
"@emotion/styled": "^11.6.0",
"@mui/icons-material": "^5.3.1",
"@mui/lab": "^5.0.0-alpha.68",
"@mui/material": "^5.4.0",
"@testing-library/jest-dom": "^5.16.1",
"@testing-library/react": "^12.1.2",
"@testing-library/user-event": "^13.5.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "5.0.0",
"web-vitals": "^2.1.4"
},
但是每次我都会得到以下错误:
编译有问题: ERROR in ./node_modules/@date-io/date-fns/build/index.esm.js 1:0-39 找不到模块:错误:无法解析'C:\Users\Amir\Desktop\React\React-apps\expense-tracker\node_modules\@date-io\date-fns\build'中的'date-fns/addDays' ERROR in ./node_modules/@date-io/date-fns/build/index.esm.js 2:0-45 找不到模块:错误:无法解析'C:\Users\Amir\Desktop\React\React-apps\expense-tracker\node_modules\@date-io\date-fns\build'中的'date-fns/addSeconds' ...
我在网上搜索了一下,但没有找到有用的东西。还有一些类似的StackOverflow帖子建议重新启动服务器,我尝试了但并没有真正解决我的问题。