Closed soroushm closed 6 years ago
You need date fns 2.0 Install it like npm i date-fns@next
@dmtrKovalenko Please add npm install date-fns@next -S
in Documentation in Installation Section
@dmtrKovalenko Why not add date-fns as a peer dependency? At least then yarn would complain.
@andrew-w-ross Because we have a dependency moment OR date-fns
@dmtrKovalenko Thank you for added in docs
Still won't work:
import error: 'DateFnsUtils' is not exported from 'date-fns'.
Please add document about how to use date-fns with @material-ui/pickers
Also, since moment won't work with @material-ui/pickers, why not just add date-fns into the package itself.
You need to install both date-fns@next
and @date-io/date-fns
to get it to work.
$ npm i --save date-fns@next @date-io/date-fns
@aeroxy I'll try to describe everything
1) You really need to install both @date-io/date-fns and date-fns@next 2) This library supports moment users. For moment you will need to install @date-io/moment and moment. Instead of date-fns respectively. 3) We are not adding the date-fns directly to the package in order to make possible to use moment, dayjs or luxon. But date-fns is recommended and primarily supported lib.
I see. But this is confusing. Why not just, again, add date-fns into the package itself. You can add another npm package called material-ui-pickers-pure
or material-ui-pickers-bare
without date-fns libs.
Yeah I don't really get the thinking behind having the provider in general. Having to wrap everything in <MuiPickersUtilsProvider utils={DateFnsUtils}>
makes no sense. Better to pull the required date-fns as a dependency of the component. Cleaner code and better DX.
We got bit by this. We lost considerable time trying to understand the what
and the why
of this.
My team and I are in full support of @aeroxy 's suggestion.
We will not get out of current solution at least for now You need to wrap the component only 1 time. A lot of developers using moment (60%) but a lot of users don't want to. This is the only solution for that
Environment
Steps to reproduce
date-fns have folder like
add_days
Expected behavior
import parse from 'date-fns/parse'; import addDays from 'date-fns/add_days'; import addMonths from 'date-fns/add_months'; import addYears from 'date-fns/add_years'; import endOfDay from 'date-fns/end_of_day'; import endOfMonth from 'date-fns/end_of_month'; import endOfWeek from 'date-fns/end_of_week'; import endOfYear from 'date-fns/end_of_year'; import format from 'date-fns/format'; import isAfter from 'date-fns/is_after'; import isBefore from 'date-fns/is_before'; import isSameDay from 'date-fns/is_same_day'; import isValid from 'date-fns/is_valid'; import setDay from 'date-fns/set_day'; import setHours from 'date-fns/set_hours'; import setMinutes from 'date-fns/set_minutes'; import setYear from 'date-fns/set_year'; import startOfDay from 'date-fns/start_of_day'; import startOfMonth from 'date-fns/start_of_month'; import startOfWeek from 'date-fns/start_of_week'; import startOfYear from 'date-fns/start_of_year'; import getHours from 'date-fns/get_hours'; import getYear from 'date-fns/get_year'; import isEqual from 'date-fns/is_equal';
Actual behavior
import parse from 'date-fns/parse'; import addDays from 'date-fns/addDays'; import addMonths from 'date-fns/addMonths'; import addYears from 'date-fns/addYears'; import endOfDay from 'date-fns/endOfDay'; import endOfMonth from 'date-fns/endOfMonth'; import endOfWeek from 'date-fns/endOfWeek'; import endOfYear from 'date-fns/endOfYear'; import format from 'date-fns/format'; import isAfter from 'date-fns/isAfter'; import isBefore from 'date-fns/isBefore'; import isSameDay from 'date-fns/isSameDay'; import isValid from 'date-fns/isValid'; import setDay from 'date-fns/setDay'; import setHours from 'date-fns/setHours'; import setMinutes from 'date-fns/setMinutes'; import setYear from 'date-fns/setYear'; import startOfDay from 'date-fns/startOfDay'; import startOfMonth from 'date-fns/startOfMonth'; import startOfWeek from 'date-fns/startOfWeek'; import startOfYear from 'date-fns/startOfYear'; import getHours from 'date-fns/getHours'; import getYear from 'date-fns/getYear'; import isEqual from 'date-fns/isEqual';
and now get a new error