Jake Chavez
Jake Chavez

Reputation: 35

React Moment problem on DatePicker when using moment (Maybe dependencies)

I'm using DatePicker and I can't set the default Values, I tried this:

I import the moment like this:

import moment from 'moment';

//And then: 

<DatePicker 
   defaultValue={moment('2015/01/01', 'YYYY/MM/DD')}
/>

//Also tried this

<DatePicker 
   defaultValue={moment('2015/01/01')}
/>

But I got this error: "Type 'import("C:/git/my_project/node_modules/moment/moment").Moment' is not assignable to type 'moment.Moment'. Types of property 'add' are incompatible."

I can't find where is my error

When I type npm ls moment and npm ls @types/moment. This is the result:

https://i.sstatic.net/ZXfXr.png

Upvotes: 2

Views: 2153

Answers (1)

FrenchMajesty
FrenchMajesty

Reputation: 1139

In my case, I had multiple conflicting moment version. I ran npm ls moment and I got this:

├─┬ [email protected]
│ ├── [email protected] 
│ └─┬ [email protected]
│   └── [email protected]  deduped
└── [email protected] 

I also had @types/moment installed on my repository but moment now supports TypeScript (You can see a deprecation warning on the npm package page)

There are the steps I followed:

npm un --s @types/moment
npm i --s [email protected]

Install whatever version antd is dependent on to remove the errors

Upvotes: 5

Related Questions