dayjs icon indicating copy to clipboard operation
dayjs copied to clipboard

Impredictible error on first run

Open josedotjs opened this issue 2 years ago • 2 comments

Hi Nathan, i am testing the new release and have an issue with the relative time plugin, in the first run i get the error Uncaught (in promise) TypeError: $setup.$dayjs(...).fromNow is not a function After terminate the process and run npm run dev again, the project works fine. May be related with this dayjs issue https://github.com/iamkun/dayjs/issues/1242 Link to test https://stackblitz.com/edit/github-qiphrf?file=README.md (you can try terminate the first run and execute npm run dev again)

josedotjs avatar Mar 08 '23 18:03 josedotjs

I too noticed that issue, and I'm not sure why it happens. AFAIK, the module should just work as an extension of a normal Nuxt 3 plugin, like:

// /plugins/dayjs.ts
import dayjs from 'dayjs';
import relativeTime from 'dayjs/plugin/relativeTime';

dayjs.extend(relativeTime);

export default defineNuxtPlugin(() => {
  return {
    provide: {
      dayjs,
    },
  };
});

nathanchase avatar Mar 19 '23 23:03 nathanchase

Please try https://github.com/nathanchase/dayjs/releases/tag/1.0.15 and let me know if it works for you! It did for me locally.

nathanchase avatar Apr 06 '23 17:04 nathanchase