Skip to content

UseDate().format is not able to find locale #323

@skoenfaelt

Description

@skoenfaelt
  • Using a base layer as npm package witrh preconfigureed i18n and vuetify
  • in my app I add additional i18n, vuetify based on the project

the script and template
const { date, format: formatDate } = useDate()
{{ formatDate(date(auftrag.xyz[0].datestring), 'keyboardDate') }}

If I run the app in dev mode, everything works just perfect. As soon as I build the app and start it I get
"Cannot read properties of undefined (reading 'locale')"

where the error occurs

format(t, n) {
        return WP(t, n, this.locale, this.formats)
    }

minified call:

 m( () => [w("div", mt, [w("div", vt, [c[0] || (c[0] = w("span", null, "Datum: ", -1)), E(" " + F(a(h)(a(g)(t.auftrag.xyz[0].datestring), "keyboardDate")), 1)])

so its 100% the format of useDate composable.

I tried different date adapters, vuetify, luxon, dayJs. A reproduction is hard to recreate. Are there any special configs I need to look into?

If used with DayJs I get this error:
Cannot read properties of undefined (reading 'dayjs')


If I use native Luxon adapter

  import { DateTime } from 'luxon'

  const { locale } = useI18n()
  const formatDate = (dateString: string) => {
    return DateTime.fromISO(dateString).setLocale(locale.value).toLocaleString(DateTime.DATE_MED)
  }

then everything works.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions