【问题标题】:Material UI Picker - date-fns issue材质 UI 选择器 - 日期-fns 问题
【发布时间】:2019-01-23 13:05:32
【问题描述】:

我在我的 React 应用程序中使用 Material UI,我很难让 material-ui-pickers 示例工作。 这是 Material UI 的在线示例。 https://codesandbox.io/s/52p74362pl

我得到的错误是:

 index.js:1446 ../node_modules/@date-io/date-fns/build/index.esm.js Module not found: `Can't resolve 'date-fns/addDays' in 'C:\Project4\CDE\IFS.CDE.Web\node_modules\@date-io\date-fns\build'`

这是我的 package.json 文件

{
  "name": "IFS.CDE.Web",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@material-ui/core": "^3.7.1",
    "@material-ui/icons": "^3.0.1",
    "ajv": "^6.5.2",
    "autosuggest-highlight": "^3.1.1",
    "axios": "^0.18.0",
    "classnames": "^2.2.5",
    "connected-react-router": "6.1.0",
    "date-fns": "^1.30.1",
    "downshift": "^2.0.10",
    "extract-svg-path": "^2.1.0",
    "file-saver": "^1.3.8",
    "install": "^0.12.1",
    "lodash": "^4.17.10",
    "material-ui-datetimepicker": "^1.0.7",
    "material-ui-image": "^3.0.3",
    "material-ui-pickers": "^2.1.1",
    "moment": "^2.23.0",
    "npm": "^6.5.0",
    "parse-svg-path": "^0.1.2",
    "prop-types": "^15.6.2",
    "rc-progress": "^2.2.6",
    "react": "^16.6.3",
    "react-autosuggest": "^9.3.4",
    "react-bingmaps": "^3.6.1",
    "react-color": "^2.14.1",
    "react-dnd": "^7.0.2",
    "react-dom": "^16.6.3",
    "react-dropzone": "^4.3.0",
    "react-file-viewer": "^0.5.0",
    "react-iframe": "^1.2.0",
    "react-loadable": "^5.5.0",
    "react-popper": "^0.10.1",
    "react-redux": "^6.0.0",
    "react-render-html": "^0.6.0",
    "react-router-dom": "^4.3.1",
    "react-scripts": "^2.1.2",
    "react-select": "^2.0.0",
    "redux": "^4.0.1",
    "redux-persist": "^5.10.0",
    "redux-thunk": "^2.3.0",
    "rimraf": "^2.6.2",
    "typeface-roboto": "^0.0.54",
    "uuid": "^3.3.2",
    "video-react": "^0.13.1"
  },
  "scripts": {
    "start": "rimraf ./build && react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject",
    "set-env": "set NODE_ENV=production"
  },
  "devDependencies": {},
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ]
}

我已经安装了 date-fns 但我仍然收到错误。 https://www.npmjs.com/package/date-fns。 我还删除了所有节点模块并进行了 npm install 以查看是否可以解决问题,但没有解决。

感谢您的帮助。

【问题讨论】:

  • 查看如何使用它的代码示例可能会有所帮助。如果您可以在沙盒上复制问题并将其链接起来,那就更好了。像这样的问题太模糊,无法猜测解决方案。
  • 请添加您的依赖项/package.json

标签: javascript reactjs npm


【解决方案1】:

安装这个(见here):

npm i --save date-fns@next @date-io/date-fns

【讨论】:

    【解决方案2】:

    尝试使用date-fns 2.0.0。我有同样的问题并通过更新库修复。希望它有效。

    【讨论】:

      猜你喜欢
      • 2020-08-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-03
      • 2017-07-02
      • 1970-01-01
      • 2016-10-01
      • 1970-01-01
      相关资源
      最近更新 更多