Leff7's avatar
Level 4

Javascript - Export default was not found

I have a project build in Vue 2, and I made a simple function for translating months in dates, which I would like to import in one of my components, but I get an error:

"export 'default' (imported as 'translateDate') was not found in '@/utils/date-translation'

The relative file path from the src folder is correct, and I am exporting the function like this:

export function translateDate(date) {
   ....code
}

And then I am importing it in the component like this:

<script>
  import translateDate from '@/utils/date-translation';
  export default {
    name: 'tile',
    props: ['article', 'main'],
    data() {
      return {}
    },
    computed: {
      createdAt() {
        return translateDate(this.article.created_at.date.substring(0, 10));
      }
    }
  };

What am I doing wrong?

0 likes
1 reply
sebwas's avatar

Hi,

using this line import translateDate from '@/utils/date-translation' you basically tell JS to import the default exported object from the file and use it under the name translateDate.

What you can do instead is export it as a default like this:

export default function translateDate(date) {
    // ....code
}

The other possibility of what you can do in this situation is importing it like this:

import { translateDate } from '@/utils/date-translation'

However if you only have one piece of functionality in there you should go with #1.

More information can be found here.

Please or to participate in this conversation.