dmtrKovalenko / date-io

Abstraction over common javascript date management libraries
MIT License
726 stars 90 forks source link

Module not found: Error: Can't resolve 'date-fns/formatISO' #601

Closed enoch-prince closed 2 years ago

enoch-prince commented 2 years ago

Hi, I run into the this error and have been trying to find a solution for it for days now.

Below are my dependencies from my package.json

"dependencies": {
    "@date-io/date-fns": "latest",
    "@emotion/react": "latest",
    "@emotion/styled": "latest",
    "@mui/lab": "latest",
    "@mui/material": "latest",
    "@types/jest": "latest",
    "@types/node": "latest",
    "@types/react": "latest",
    "@types/react-dom": "latest",
    "date-fns": "latest",
    "history": "latest",
    "react": "latest",
    "react-dom": "latest",
    "react-icons": "latest",
    "react-router-dom": "latest",
    "react-scripts": "^5.0.0",
    "typescript": "latest"
  }

I used the same example for the DatePicker from the mui/lab documentation, but I got this error.

Node version - v14.17.0 NPM version - 8.3.0

Any clue on how to fix this?

rkeene commented 2 years ago

This error could happen if you haven't installed a compatible version of the peer dependencies.

   "name": "@date-io/date-fns",
   "peerDependencies": {
     "date-fns": "^2.0.0"
   },
   "peerDependenciesMeta": {
     "date-fns": {
       "optional": true
     }
   },

Older versions of date-fns lack formatISO() (also, it's not clear why this peer dependency is optional -- since it seems to be really important to the functioning of this package).

To fix this, you can install a newer version of date-fns that has formatISO as a peer dependency of '@date-io/date-fns', e.g.:

$ npm install 'date-fns@^2.0.0'