首页 > 解决方案 > 未找到模块:无法在 React 中解析“@date-io/date-fns”

问题描述

我正在使用 React Material UI 并收到此错误:找不到模块:无法解析“@date-io/date-fns”。

以下是我的 package.json 文件中的依赖项:

  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@material-ui/core": "^4.12.1",
    "@material-ui/icons": "^4.11.2",
    "@material-ui/pickers": "^3.3.10",
    "@testing-library/jest-dom": "^5.11.8",
    "@testing-library/react": "^11.2.2",
    "@testing-library/user-event": "^12.6.0",
    "antd": "^4.16.6",
    "axios": "^0.21.1",
    "bootstrap": "^4.5.3",
    "query-string": "^4.3.4",
    "react": "^17.0.1",
    "react-bootstrap": "^1.4.0",
    "react-dom": "^17.0.1",
    "react-owl-carousel": "^2.3.3",
    "react-router-dom": "^5.2.0",
    "react-script-tag": "^1.1.2",
    "react-scripts": "4.0.1",
    "react-seat-picker": "^1.5.3",
    "react-tooltip": "^4.2.21",
    "web-vitals": "^0.2.4"
  },

我尝试安装这些库,但它一直在命令提示符下显示错误

D:\WebSites\site>npm i --save date-fns@next @date-io/date-fns
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: site@0.1.0
npm ERR! Found: date-fns@2.0.0-beta.5
npm ERR! node_modules/date-fns
npm ERR!   date-fns@"2.0.0-beta.5" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peerOptional date-fns@"^2.0.0" from @date-io/date-fns@2.11.0
npm ERR! node_modules/@date-io/date-fns
npm ERR!   @date-io/date-fns@"*" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See C:\Users\Ryan\AppData\Local\npm-cache\eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Ryan\AppData\Local\npm-cache\_logs\2021-08-11T12_31_59_156Z-debug.log

标签: reactjsmaterial-uidatetimepicker

解决方案


安装这个包对我有用。

日期-fns

npm i date-fns

推荐阅读