Date picker documentation needs to be updated
See original GitHub issue“@material-ui/core”: “^4.4.0”, “@material-ui/icons”: “^4.2.1”, “@material-ui/pickers”: “^3.2.2”, “react”: “^16.9.0”, “react-dom”: “^16.9.0”, “react-router-dom”: “^5.0.1”, “react-scripts”: “3.1.1”, “typescript”: “^3.6.2”
Steps to reproduce
The documentation for the date picker doesn’t work and the three closed issues I reviewed for the error don’t resolve the problem for me. I’m unsure what the actual fix is for this.
The documentation is using import DateFnsUtils from '@date-io/date-fns';
. If I use the current version of 1.3.11
, I get the Can't resolve 'date-fns/addDays'
error mentioned below.
This issue says to use date-fns
version 2.x
. So I installed "date-fns": "^2.2.1"
and imported it as import * as DateFnsUtils from 'date-fns';
. In doing so I get the error: Cannot find module '@date-io/core/IUtils'
.
This issue says to use date-fns@1.30.1
. So I installed that version. I get the same Cannot find module '@date-io/core/IUtils'
error.
At this point I decided to install "@date-io/core": "^1.3.11"
. Running with that, I get the error: Cannot find module '@date-io/type'
. I attempted to install that and the package doesn’t appear to exist.
I also tried installing "date-fns": "^2.2.1"
with "@date-io/core": "^1.3.11"
, but I still get the Cannot find module '@date-io/type'
error.
[Edit 1] Looking at the type definitions for MuiPickersUtilsProvider
; I noticed that’s importing import { IUtils } from '@date-io/core/IUtils';
. IUtils
has a moment
property, so I thought I’d try passing moment
in as the MuiPickersUtilsProvider.utils
property. I still end up with the Cannot find module '@date-io/type'
error.
[Edit 2] I realized I should check out the CodeSandbox for the example. That appears to be working, however when I try to install the same packages it uses, neither @types/date-ioDate-fns
nor @types/material-uiPickers
appear to exist. No matter what packages I try, I still run into the Cannot find module '@date-io/type'.
error.
I’m at a loss here. 😦
Expected behavior
If I follow the documentation I shouldn’t get errors.
Actual behavior
Getting error: Can't resolve 'date-fns/addDays'
. Closed issue here.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:7 (3 by maintainers)
Top GitHub Comments
As a side note: if one or more of these
date-fns
packages is a requirement of using the date picker, why aren’t they added as dependencies in the@material-ui/pickers
package so we don’t have to worry about what we’re supposed to install to pass to the provider (<MuiPickersUtilsProvider utils={DateFnsUtils}>
)?In regards to [Edit 1] in the OP, if it’s not included because you can pass in
moment
instead, that makes sense. I already had moment installed because I needed good UTC support and it doesn’t appeardate-fns
format
is there yet.Here https://material-ui-pickers.dev/demo/datepicker#dynamic-data And here https://material-ui-pickers.dev/demo/datepicker#customization