
| Tech | Version |
| -------------------- | ------- |
| @material-ui/pickers | 3.0.0 |
| material-ui | 4.0.1 |
| React | 16.8.5 |
| Browser | irrelevant |
| Peer library | date-fns@next | |
create a project with ts and react
install @material-ui/picker
use the DatePicker with the provider and try to build it
should fail
My app should build 💃
../../node_modules/@material-ui/pickers/DatePicker/components/YearSelection.d.ts:2:26 - error TS2307: Cannot find module '@date-io/type'.
2 import { DateType } from '@date-io/type';
~~~~~~~~~~~~~~~
../../node_modules/@material-ui/pickers/typings/date.d.ts:1:26 - error TS2307: Cannot find module '@date-io/type'.
1 import { DateType } from '@date-io/type';
~~~~~~~~~~~~~~~
From what i saw the type DateType does not exist on @date-io/type (because @date-io/type does not exist)
We should create this type manually instead of trying to import it from a place that doesnt exist.
Or maybe i just missed some steps or i forgot something but i hope not, it would be embarrassing 🤣!
Yeeah, it is included in @date-io/{lib} package. Please mention the version of @date-io/date-fns you using. It should be at least 1.3.5
Hi 👋
my version is:@date-io/date-fns^1.3.6
And you have imported it?
Of course
// in my component
import { combineReducers } from "redux";
import { Paper, Typography } from "@material-ui/core";
import DateFnsUtils from '@date-io/date-fns';
import React from "react";
...
But where is the package @date-io/lib ? i can't seem to find it.
Actually it is imported right from @date-io/date-fns
Here is https://github.com/dmtrKovalenko/date-io/tree/master/packages/date-fns/type
Actually one thing you need is to make
declare module "@date-io/type" {
export type DateType = Date;
}
Just checked out the source of @material-ui/pickers
you have a typings.d.ts file that has :
declare module '@date-io/type' {
import { Moment } from 'moment';
import { DateTime } from 'luxon';
export type DateType = Moment | DateTime | Date;
}
And you specified in the tsconfig that you want it included in the build :
{
...
"include": ["src/**/*.ts*", "typings.d.ts"],
"exclude": ["./src/__tests__/**/*", "build"]
...
}
But actually it is not included at all
It is useed only for the local build. Included in @date-io/date-fns or any other @date-io/* lib
Checkout this codesandbox - everything works with ts. And type is inferred https://codesandbox.io/s/elated-hertz-uzbdb
So i just checked it, and locally it works too (i use storybook) but when i try to build it fails because of the types he can't find.
The command tsc fails everytime :'(
Try to redeclare the type manually
thats one of the first things i tried actually... !
Right now as a temporarily "fix" i added "skipLibCheck": true, to my tsconfig file because we are using it in a project that we use at my company and we need build to pass :D
But i'm going to look into it today or tomorrow for an alternative) because i do not want to have this options set !
Closing due to silency
@dmtrKovalenko I am seeing the same thing with @date-io/[email protected] and there is no @date-io/lib installed locally (mentioned in https://github.com/mui-org/material-ui-pickers/issues/1074#issuecomment-497763923)
As far as I can tell, the only occurrence I have of this is in node_modules/@date-io/date-fns/type as a manual type declaration or augmentation.
I'm now confused. Where is the source of @date-io/type and why is it referred to as a package when it is neither published nor installed as such?
Ah, I think I see now.
https://github.com/mui-org/material-ui-pickers/issues/1074#issuecomment-498009348
This seems like a missing part of the setup to use the adapter libraries. The documentation site is down so I can't see if it is there.
I want to leave this open to confirm this is part of the docs.
Yeah this is kinda workaround. When you import any @date-io lib — it will also import and create fake ts-only module with DateType.
I know that it’s a bit flaky solution. But it worked well for me.
We just need to make sure it is in the docs for ts users. Are you aware the docs site is down?
It is down???? 😱😱😱
https://share.icloud.com/photos/0xRwVgGavaZAOIv4DmcCCq5bA
For me it is working
And google analytics says that there are 5 active users right now
I'm in the central US and it is unreachable. IP resolves as:
nslookup material-ui-pickers.dev
Server: 2001:558:feed::1
Address: 2001:558:feed::1#53
Non-authoritative answer:
Name: material-ui-pickers.dev
Address: 35.243.186.38
Ohh 😮
I will contact zeit now guys.
FYI - still cannot get to https://material-ui-pickers.dev/
Ok, to get this to work reliably, it seems we need to do the following:
declare module '@date-io/type' {
export type DateType = Date
}
with appropriate additions to the tsconfig to enable type augmentation.
tsc locally in my app is both a) complaining about this file missing; and b) complaining that when I add it that it duplicates the definition found in node_modules and in my augmentation:Executing task: /Users/kross/projects/js/node_modules/.bin/tsc -b /Users/kross/projects/js/tsconfig.json <
node_modules/@date-io/date-fns/type/index.d.ts:2:15 - error TS2300: Duplicate identifier 'DateType'.
2 export type DateType = Date;
~~~~~~~~
typings/date-io.d.ts:2:15
2 export type DateType = Date
~~~~~~~~
'DateType' was also declared here.
I think it best to exclude this augmentation from the published package so as to not add to user or compiler confusion. If I delete the packaged augmentation file tsc works.
I'll submit a PR for that.
Further details are here: https://github.com/dmtrKovalenko/date-io/issues/52
Though I've still not been able to solve it. Ideas are welcome.
Closing that. Here is a repo where auto-linked @date-io/type module works like a charm
yarn tsc succed
im getting this too with @date-io/luxon
node_modules/@material-ui/pickers/typings/date.d.ts:1:26 - error TS2307: Cannot find module '@date-io/type'.
1 import { DateType } from '@date-io/type';
~~~~~~~~~~~~~~~
node_modules/@material-ui/pickers/views/Year/YearView.d.ts:2:26 - error TS2307: Cannot find module '@date-io/type'.
2 import { DateType } from '@date-io/type';
~~~~~~~~~~~~~~~
please resolve
@hwatersiv I cannot be sure, but this appears to be problematic with a possible combination monorepositories or yarn workspaces and tsc. I tried removing my postinstall hack last week to see if it worked, and it did not.
All of my instances are monorepos with yarn workspaces so it is difficult for me to narrow a test case further.
Are you using a monorepo, yarn workspaces or both?
@rosskevin here is my package.json
{
"name": "components-base",
"version": "1.0.0",
"description": "Common components",
"scripts": {
"build": "npm-run-all tsc:build package",
"tsc:build": "tsc -p .",
"lint": "tslint -p tsconfig.json",
"package": "npm pack",
"start": "webpack-dev-server --open"
},
"files": [
"build"
],
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.{ts,tsx}": [
"npm run lint",
"git add"
]
},
"peerDependencies": {
"@date-io/luxon": ">=1.3.11",
"@material-ui/core": ">=4.5.0",
"@material-ui/icons": ">=4.4.3",
"@material-ui/pickers": ">=3.2.6",
"luxon": ">=1.19.3",
"react": ">=16.10.1",
"react-dom": ">=16.10.1",
"react-redux": ">=7.1.1",
"react-select": ">=3.0.8",
"redux": ">=4.0.4",
"typesafe-actions": ">=4.4.2"
},
"devDependencies": {
"@types/luxon": "^1.15.2",
"@types/react": "^16.9.6",
"@types/react-dom": "^16.9.2",
"@types/react-redux": "^7.1.4",
"@types/react-select": "^3.0.5",
"clean-webpack-plugin": "^3.0.0",
"html-webpack-plugin": "^3.2.0",
"husky": "^3.0.9",
"lint-staged": "^9.4.2",
"npm-run-all": "^4.1.5",
"ts-loader": "^6.2.0",
"tslint": "^5.20.0",
"tslint-config-prettier": "^1.18.0",
"tslint-react": "^4.1.0",
"typescript": "^3.6.4",
"webpack": "^4.41.2",
"webpack-cli": "^3.3.9",
"webpack-dev-server": "^3.8.2",
"@date-io/luxon": "^1.3.11",
"@material-ui/core": "^4.5.1",
"@material-ui/icons": "^4.5.1",
"@material-ui/pickers": "^3.2.7",
"luxon": "^1.19.3",
"react": "^16.10.2",
"react-dom": "^16.10.2",
"react-redux": "^7.1.1",
"react-select": "^3.0.8",
"redux": "^4.0.4",
"typesafe-actions": "^4.4.2"
}
}
For Clarity:
The package is the only thing in the repo.
No Im not using yarn
For me the missing type was added after configuring the locale
import { MuiPickersUtilsProvider } from '@material-ui/pickers';
import MomentUtils from '@date-io/moment';
import moment from 'moment';
import 'moment/locale/pl';
moment.locale('pl');
...
<MuiPickersUtilsProvider utils={MomentUtils} locale="pl">
...
The missing type comes with @date-io/moment
Since importing @date-io/luxon results in @date-io/type being defined, I fixed this by adding this to my typings file:
import '@date-io/luxon';
Most helpful comment
im getting this too with
@date-io/luxonplease resolve