Skip to content

Commit 009a732

Browse files
fix: isDayjs import usage for ESM (#2924)
### 🎯 Goal _Describe why we are making this change_ recently we moved our stack to ESM (micro frontends, uses import maps). Noticed we are getting below error in the micro-frontend that uses `stream-chat-react`, ``` Failed to load module mfe-chat SyntaxError: The requested module 'dayjs' does not provide an export named 'isDayjs' (at index.umd-ce148d01.js:18:14) ``` on further investigation, found: - `isDayjs` is actually not exported in `dayjs` esm build. It needs to be accessed to through `dayjs` instance. - We are using importmap (esm), to satisfy `dayjs` dependency, this fails because of improper import of `isDayjs` simply create `index.html`, with below code and run it **this will fail,** ```html <script type="module"> import { isDayjs } from "https://cdn.jsdelivr.net/npm/dayjs@1.10.4/+esm"; console.log(isDayjs); </script> ``` **this will pass,** ```html <script type="module"> import Dayjs from "https://cdn.jsdelivr.net/npm/dayjs@1.10.4/+esm"; console.log(Dayjs.isDayjs); </script> ``` related ticket in dayjs, iamkun/dayjs#1306 ### 🛠 Implementation details _Provide a description of the implementation_ - fix import usage ### 🎨 UI Changes _Add relevant screenshots_ Co-authored-by: Anton Arnautov <43254280+arnautov-anton@users.noreply.github.com>
1 parent 706978b commit 009a732

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/i18n/utils.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Dayjs, { isDayjs } from 'dayjs';
1+
import Dayjs from 'dayjs';
22
import type { Duration as DayjsDuration } from 'dayjs/plugin/duration';
33

44
import type { TFunction } from 'i18next';
@@ -100,7 +100,9 @@ export const predefinedFormatters: PredefinedFormatters = {
100100
durationFormatter:
101101
(streamI18n) =>
102102
(value, _, { format, withSuffix }: DurationFormatterOptions) => {
103-
if (format && isDayjs(streamI18n.DateTimeParser)) {
103+
// NOTE: isDayjs is not exported in "dayjs" package for ESM, hence we access
104+
// `isDayjs` from Dayjs instance
105+
if (format && Dayjs.isDayjs(streamI18n.DateTimeParser)) {
104106
return (streamI18n.DateTimeParser.duration(value) as DayjsDuration).format(
105107
format,
106108
);

0 commit comments

Comments
 (0)