Search code examples
sveltesapperdayjs

Using dayjs with Sapper


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

Solution

  • 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.