0

I have been using moment.js in a page in my Sapper app. When I build the project, I noticed that moment.js takes up quite some space, so I tried to switch over to dayjs instead.

However, whenever I try to open the page in which I am using day.js, the page simply fails and says that it is taking a long time to respond. Any ideas why this is happening?

Steps to reproduce

  • get the Sapper project
  • npm install dayjs
  • use it in any page, and observe the behavior

Info

  • Day.js Version: 1.8.34
  • OS: Linux Mint 19.3 (Cinnamon 4.4.8)
  • Browser: Chrome 80.0
psc212
  • 73
  • 2

1 Answers1

0

I just test it and it's working fine if you import it as a module:

<script>
  import dayjs from "dayjs";

  console.log(dayjs("2018-08-08"));
</script>

You will see in the console something like:

{
  $L: "en"
  $d: Wed Aug 08 2018 00:00:00 GMT+0200 (Central European Summer Time)
  $y: 2018
  $M: 7
  ...
}

Checkout the sapper codesandbox and the classic svelte codesandbox to see it live.

johannchopin
  • 13,720
  • 10
  • 55
  • 101
  • How do you load plugins for `dayjs` as required for the `dayjs().week()` method (which requires loading the `weekOfYear` plugin [ref](https://day.js.org/docs/en/get-set/week))? – Thismatters Aug 08 '22 at 17:10
  • @Thismatters I have the code for that but doesn't fit as a comment. Could you please open a new question and post the link of it here? I will share you the code there. – johannchopin Aug 09 '22 at 08:06