metonym / svelte-time

Svelte component and action to format a timestamp using day.js
https://metonym.github.io/svelte-time
MIT License
137 stars 8 forks source link

Uncaught SyntaxError: ambiguous indirect export: default #28

Open norricorp opened 1 year ago

norricorp commented 1 year ago

Hello, I wonder if you can help with this.

Here are snippets of my code

  import Time, { svelteTime } from "svelte-time";
  import { dayjs } from "svelte-time";
......
{#if first}
    <p>
      {first.publish_date} 
      <time
          use:svelteTime="{{
          timestamp: first.publish_date,
        }}"
      />
     </p>
{/if}

without the svelteTime code, all is well, first.publish_date is printed. With the extra code, I get an error in firefox console of above. It is a line two of days.js.

So I changed first.publish_date with "2021-02-14" and got the same error. Obviously this works in the repl.

Any ideas what I am doing wrong?

norricorp commented 1 year ago

Just to add, I commented out the time tag. Still same error. So then I commented out the import lines and now it works. (obvioulsy without the svelte-time code)

metonym commented 1 year ago

What set-up are you using? If SvelteKit, what version?

norricorp commented 1 year ago

Hi @metonym, thanks for getting back so quickly. I am not using sveltekit. I am using svelte 3.49.0. Running on windows 10. Is there anything you want?

norricorp commented 1 year ago

So the problem is "Usage with Vite". I needed to add

 optimizeDeps: {
      include: ["dayjs/plugin/relativeTime.js"],
    },

to vite.config.js

Perhaps edit docs to say if get ambiguous indirect error then make sure vite.config.js is updated.

metonym commented 1 year ago

Glad you got it working. Marking this as a dupe of #27, #24.

FWIW, I believe that @sveltejs/vite-plugin-svelte version >=1.3.0 will automatically optimize these dependencies, meaning it's no longer required.