Export default was not found

JavascriptImportModuleEcmascript 6vue.js

Javascript Problem Overview


I have a Vue 2 project, and I've written a simple function for translating months in dates, which I would like to import in one of my components, but I'm getting 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) {
  // my code
}

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

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

What am I doing wrong?

Javascript Solutions


Solution 1 - Javascript

You have to specify default explicitly:

export default function translateDate(date) {
   ..
}

Solution 2 - Javascript

Either specify default as mentioned above, or if you're trying to export multiple items from the same file you need to import them with curly brackets.

So you would have:

export function doWork(){}
export const myVariable = true;

And then you'd import them in a separate file as:

import { doWork, myVariable} from "./myES6Module"

Solution 3 - Javascript

In my case I had to remove '{' and '}' arround the imported component :

import { CustomComponent } from './CustomComponent';

with

import CustomComponent from './CustomComponent';

Solution 4 - Javascript

You need to set symlink setting in vue.config.js

config.resolve.symlinks(false);

Solution 5 - Javascript

Maybe you have two files with the same name.For example, "test.vue" and "test.js"

Solution 6 - Javascript

Rather than using

   export function translateDate(date) {
  // my code
}
 

use

     function translateDate(date){
         //code
          }

export default translateDate;

it worked for me...

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLeffView Question on Stackoverflow
Solution 1 - JavascriptDanil SperanskyView Answer on Stackoverflow
Solution 2 - JavascriptAlex DView Answer on Stackoverflow
Solution 3 - JavascriptpushStackView Answer on Stackoverflow
Solution 4 - JavascriptFarid VataniView Answer on Stackoverflow
Solution 5 - JavascriptdangdangdanglllView Answer on Stackoverflow
Solution 6 - JavascriptJason Dsouza013View Answer on Stackoverflow