dayjs
dayjs copied to clipboard
Nuxt 3 - dayJs(...).tz(...).guess is not a function
I have an issue accessing guess with the timezone for Nuxt 3.
config:
export default defineNuxtConfig({
modules: ['dayjs-nuxt'],
dayjs: {
locales: ['en'],
plugins: ['relativeTime', 'utc', 'timezone'],
defaultLocale: 'en',
defaultTimezone: 'America/New_York',
},
});
Reproduction:
https://stackblitz.com/edit/nuxt-starter-xkk6vr?file=app.vue
thanks for the stackblitz, you might just be calling the composaible wrong, try this:
<template>
<div>current timezone: {{ getTimezone() }}</div>
</template>
<script setup>
const dayJs = useDayjs();
const getTimezone = () => {
return dayJs.tz.guess();
};
</script>
also it might not be required but if you run into issues you may need to add this dep:
"devDependencies": {
"dayjs": "^1.11.12",
"dayjs-nuxt": "^2.1.9"
}