我正在尝试添加并使用Moment Precise Range插件来使用其主函数preciseDiff
。
我有Angular 12项目。
在我的包.json中,我有:
"moment": "2.29.4",
"moment-precise-range": "0.2.0",
使用该插件的内部组件我有:
import * as moment from 'moment';
import 'moment-precise-range';
declare module 'moment' {
function preciseDiff(start: string | Date | moment.Moment, end: string | Date |
moment.Moment, convertToObject?: boolean): any;
}
然后我调用preciseDiff
函数:
moment.preciseDiff(endDate, now, true)
代码编译了,但我有这个错误:
错误类型错误:moment__WEBPACK_IMPORTED_MODULE_4__。preciseDiff为不是功能
我尝试了这个Stack Overflow帖子中的解决方案,但没有成功。当我更换时
import 'moment-precise-range';
带有
import 'moment-precise-range-plugin';
正如那里所建议的那样,我的代码甚至不会编译。
错误:无法解决"瞬间精确范围插件">
当我更改实际插件时(在package.json中(来自:
"moment-precise-range": "0.2.0",
至:
"moment-precise-range-plugin": "1.3.0",
我让它工作起来了,但后来,根据@MikeOne的评论,我尝试了date-fns
插件,这个插件工作得很好,不需要任何黑客攻击。所以我要从js时刻切换到那个时刻。