Dayjs: Cannot read property 'relativeTime' of undefined

Created on 19 Feb 2019  ·  4Comments  ·  Source: iamkun/dayjs

Getting the following error:

Uncaught TypeError: Cannot read property 'relativeTime' of undefined
    at fromTo (index.js:21)
    at Dayjs.push../node_modules/dayjs/esm/plugin/relativeTime/index.js.__webpack_exports__.default.proto.from (index.js:89)
    at Module../src/app/core/utils/dayjs.ts (dayjs.ts:9)

While trying to run the code:

import _dayjs from 'dayjs/esm';
import relativeTime from 'dayjs/esm/plugin/relativeTime';
import 'dayjs/locale/en';
import 'dayjs/locale/he';

_dayjs.locale('he');
_dayjs.extend(relativeTime);

console.log(_dayjs().from(_dayjs('1990'))); // <-- Fails

Running "dayjs": "^1.8.6"

released ☢️Bug

Most helpful comment

:tada: This issue has been resolved in version 1.8.8 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

All 4 comments

This is a bug.

Current workaround

import he from  'dayjs/locale/he';
_dayjs.locale(he);   // register manually

_dayjs.locale('he');   // use in other place

:tada: This issue has been resolved in version 1.8.8 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

v1.8.16 也出现了此问题, 使用上面的方案也可解决
使用的语言是 zh-cn

@bdoycn 这是一个 1.8.8 版本就 fix 了的bug 如果1.8.16 还有问题 请详细描述一下,谢谢。

Was this page helpful?
0 / 5 - 0 ratings