Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i fix error "A default export must be at the top level of a file or module decleration" in vue.js

I am getting this error when trying to scramble a word in vue.js using "shuffle" from the lodash library. This is the code that is causing the issue.

import { shuffle } from 'lodash'

// Get word of the day
const answer = getWordOfTheDay();

// scramble word of the day
export default {
  data() {
    return {
      word: answer,
      scrambledWord: ''
    }
  },
  methods: {
    scrambleWord(word) {
      return shuffle(word.split('')).join('')
    }
  }
}

I tried moving the block of code around and changing the order of things but i still get the same error. highlighted on the the "export default" part.

like image 759
William Squibb Avatar asked Nov 24 '25 17:11

William Squibb


1 Answers

In case someone is wondering, one of the most common reasons this happens is when the attribute "setup" is left in the script tag.

like image 111
Mélanie Gravel Avatar answered Nov 26 '25 09:11

Mélanie Gravel