I'm quite new to Angular and within our project, we switched recently to Angular 14.2.12. We use moment.js for time based calculation and date time parsing. But after switching to Angular 14, we got optimization bailout warnigs because of moment.js:
Warning: C:\Users\**\worklist\worklist.component.ts depends on 'moment'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
The moment.js project itself recommends on its project status page (https://momentjs.com/docs/#/-project-status/) to switch to another date library which is better suited for the modern tree-shaking algorithms etc.
We decided to use dayjs, as it seems to be very similar in syntax to moment.js. But after adding dayjs to our project and switch the usage from moment.js to dayjs, again the optimization warning showed up in the logs, now complaining about dayjs:
Warning: C:\Users\**\worklist\worklist.component.ts depends on 'dayjs'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
In the mentioned components, we use dayjs like this:
import dayjs from 'dayjs';
.
.
.
this.importantDate = dayjs(json.impDate, 'YYYY-MM-DD').format(DATE_FORMAT)
I thought the dayjs library comes as an ES6 library and not in the CommonJS library format.
I tried to use another import syntax like in the dayjs documentation:
import * as dayjs from 'dayjs'
That didn't work.
Is there something wrong in how I'm referencing the library?
I tried to use another import syntax like in the dayjs documentation:
import * as dayjs from 'dayjs'
That didn't work.