I am getting the following syntax error when I try to run a build on my Vue app.
error in ./src/pages/Calendar.vue?vue&type=script&lang=ts&
Syntax Error: 'return' outside of function. (175:4)
173 | getEventColor(event, Event);
174 | {
> 175 | return event.color;
| ^
176 | }
The component itself has the following code.
getEventColor (event: Event) {
return event.color
}
The code above does not have the syntax error getEventColor(event, Event); so I am completely confused by the error saying that the return is 'outside' the function when it clearly isn't.
Also, the actual line the function is on is not 173 but 441. Line 173 is in the middle of my <template>.
The component itself is a Veutify calendar. Here is the template that refers to the getEventColor function.
<v-calendar
ref="calendar"
v-model="focus"
color="primary"
:events="events"
:event-color="getEventColor"
:now="today"
:type="type"
@click:event="showEvent"
@click:more="viewDay"
@click:date="viewDay"
@change="updateRange"
></v-calendar>
If anyone has any guidance on this issue I'd be very grateful.
@vue/cli) or vite? Have you played with its config? Could you repro this on codesandbox?getEventColor (event: Event) {is compiled togetEventColor(event, Event);means that isn't treated as a method because the syntax was messed up. The question lacks stackoverflow.com/help/mcve and the problem was probably caused by a typo which isn't shown<script>tag of the component which outputs the error. I'm fairly certain there's something wrong with that component's syntax (e.g: you might have placedgetEventColoroutside ofmethods, directly on the definition object, or something similar).getEventColoracomputed? If it is, that's the problem: computed aregetters. So they don't take arguments. If you want them to take an argument, you have to return a function, which, in turn, could take an argument.(e.g:computed: { getEventColor() { return (event: Event) => event.color } }See answers to this question for more details.