Eslint highlighting the initial function declaration within a Vue script

I'm currently creating a Vue file using a Typescript script, and encountering an unusual Eslint "error."

https://i.sstatic.net/UXv3A.png

The issue arises on line 15 with this specific complaint:

Parsing error: Unexpected token, expected ","

Interestingly, this error only occurs with the initial function definitions and not with subsequent ones within the file. It seems to be independent of any changes made to the template preceding it.

Answer №1

Have you properly set up ESLint for TypeScript? The error message indicates that it is looking for JavaScript, and TypeScript features like types are not recognized in JS.


To resolve this, make sure to include @typescript-eslint in your eslint configuration file.

For instance, in .eslintrc.json (or .eslintrc, or in YAML format), use a structure similar to the following:

{
  "root": true,
  "parser": "@typescript-eslint/parser",
  "plugins": [
    "@typescript-eslint"
  ],
  "extends": [
    "eslint:recommended",
    "plugin:@typescript-eslint/eslint-recommended",
    "plugin:@typescript-eslint/recommended",
    "@vue/typescript/recommended"
  ]
}

Additionally, ensure that you have installed the necessary libraries by running the following command:

yarn add -D eslint @typescript-eslint/parser @typescript-eslint/eslint-plugin @vue/typescript/recommended

(@typescript-eslint/parser serves as the parser, @typescript-eslint/eslint-plugin includes standard linting rules for TS, @vue/typescript/recommended offers Vue-specific rules, and of course, eslint is the core ESLint library.)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ways to automatically display the Save Changes prompt upon closing an Electron application

Currently, I am developing an Electron application. The user's progress is saved in a file within the app. I aim to implement the typical 'Save changes before closing' prompt when the user attempts to close the application without saving. A ...

Vue Bootstrap Checkbox and <b-table> with <b-form-checkbox> components combine to provide a powerful and flexible user

I am currently implementing b-form-checkbox with b-table to fetch the selected module Ids. <b-table id="module-table" :items="list.modules" :fields="fields" :busy="isBusy"> <template slo ...

What is the best way to implement conditional styling in Vue.js?

Looking to incorporate a conditional style into my Component. Here is my component: <site-pricing color="primary" currency="$" price="25" to="/purchase" > <template v-slot:title>Complete</templat ...

Shut down the tab or browser window containing information on vue

When attempting to log off a user by closing the page and browser, I encountered difficulty. 1. window.onunload; 2. window.onbeforeunload. window.onunload = function() { differTime = new Date().getTime() - beginTime; if (differTime <= 5) { cle ...

typescript import module from tsd

Generated by swagger-codegen, the file index.ts contains: export * from './api/api'; export * from './model/models'; The file tsd.d.ts includes: ... /// <reference path="path/to/index.ts" /> TypeScript version 2.2.1. Why do I ...

WebStorm raises an error saying "SyntaxError: Plugin '@typescript-eslint' failed to load as declared in '.eslintrc.cjs' » '@vue/eslint-config-typescript'."

Encountering an issue in WebStorm where every ts file in the project displays the error message: SyntaxError: Failed to load plugin '@typescript-eslint' declared in '.eslintrc.cjs » @vue/eslint-config-typescript': Unexpected token &a ...

Error: The options object provided for the Copy Plugin is invalid and does not conform to the API schema

After addressing vulnerabilities in my package.json by updating some packages, I encountered an error while running npm. The Copy Plugin package was updated as part of fixing vulnerabilities. I attempted to revert to older commits by copying the package.j ...

Incorporating TypeScript basics into the if statement post compiling

As I delve into the Angular2 Quickstart, I stumbled upon a peculiar issue within app.component.js after compiling app.component.ts using tsc (version 1.8.2): if (d = decorators[i]) I am unable to pinpoint where I may have gone wrong in configuring the qu ...

Create a prototype class in NuxtJS Vue

What is the correct way to set a class to prototype in Vue NuxtJS? I have created a plugin Here is my nuxt.config.js file: plugins: [ { src: "~/plugins/global.js" }, ], The global.js file contains: import Vue from "vue"; import CustomStore from "dev ...

The module located at "c:/Users//Desktop/iooioi/src/main/webapp/node_modules/rxjs/Rx" does not have a default export available

I am currently delving into the realm of RxJs. Even after installing rxjs in package.json, why am I still encountering an error that says [ts] Module '"c:/Users//Desktop/iooioi/src/main/webapp/node_modules/rxjs/Rx"' has no default export ...

Get the excel file from the assets using vue.js

I need some help figuring out how to download an excel file from my vue.js project. I tried the following code: <template> <div class="row mt-5"> <a href="./assets/template.xlsx" target="_blank">Downloa ...

Improved method for linking two enums with similar appearances

Currently, I use two enums as shown: enum Tab { Approved = "Approved", Pending = "Pending", Sold = "Sold", } enum ProductStatus { Approved = "Approved", Pending = "Pending", Sold = "Sold&q ...

In relation to the characteristics of an Angular Component (written in TypeScript) Class

I am attempting to create a circle on a canvas using Angular. I have followed the necessary steps and have a basic understanding of how everything works. Although my IDE is not showing any errors, when I run the code, the console displays an error stating ...

Retrieving variable values from a dynamic array

I'm struggling with setting a dynamic value within an Object. I am loading some data inside my created hook. created() { let vm = this; axios.all([ axios.get('/api/report/someUrl'), axios.get('/api/report/someUr ...

Injecting an attribute with the forbidden character "@" into the Document Object Model (DOM

Scenario I find myself needing to update some existing HTML using JavaScript, but I'm limited in that the server side is out of my control. This means that any changes must be made client-side only without altering the original HTML document. To acc ...

How to dynamically set a computed background image in Vue 2

I have several divs that I want to style with backgrounds from values stored in an array. My attempt to set the background overlay for each one by creating a computed property has not been successful: computed: { backgroundImage(url) { let ...

What is the best way to access and utilize an id within an angular component's routing system?

I am currently working on an Angular application, and this is my first experience with JS. I have a main view where I display several elements, such as movies, each of which is clickable and links to a detailed view of the movie. My question is how can I h ...

Using Typescript to create a Checkbox Grid that displays pipe-delimited values and implements a custom validation rule

I am currently working with a checkbox grid that contains pairs of AccountIds (consisting of x number of digits) and file names separated by a pipe delimiter. The file names are structured to always begin with either PRC or FE followed by a varying combin ...

Passing an HTML5 video element as a prop in Vue.js

I am attempting to pass an HTML5 video as a property from a parent component to a child component in Vuejs. Parent Component: <template> <div> <video ref="video"> <source src="@/assets/video.mp4" type= ...

Efficiently loading data in a table with a universal filter feature using Angular with PrimeNG

Recently, I managed to set up a datatable with the functionalities of both Lazy loading and global filter. Utilizing PrimeNG components for this implementation was a breeze. However, an issue surfaced where the global filter ceased to function when lazy lo ...