fumeapp / dayjs

Nuxt V3 module for Day.js
Apache License 2.0
111 stars 12 forks source link

Nuxt 3 - dayJs(...).tz(...).guess is not a function #43

Open zlayine opened 3 months ago

zlayine commented 3 months ago

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

tcampbPPU commented 3 months ago

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>
image

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"
  }