If you attempt to import dayjs into a Vue/React app using Vite you will find it fails. Vite only works with ESM modules.
I found you need to import the esm module directly and then it will work correctly with Vite run/build.
import dayjs from 'dayjs/esm/index.js'
DayJS Docs are confusing. Vite dev working OK, BUT facing errors on vite build/preview. Problem was in my code:
WRONG:
import dayjs from "dayjs";
import * as customParseFormat from "dayjs/plugin/customParseFormat";
dayjs.extend(customParseFormat);
CORRECT:
import dayjs from "dayjs";
import customParseFormat from "dayjs/plugin/customParseFormat";
dayjs.extend(customParseFormat);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With