Error Found: Unexpected Colon (:) in Vue TypeScript File

Important Update:
After thorough investigation, it appears that the issue is directly related to the boilerplate being used. As a temporary solution, it is recommended not to extract the TypeScript file but keep it within the .vue file for now.

In a simple Vue test project, I encountered this error:

ERROR  Failed to compile with 1 errors
error  in ./src/App.ts
Syntax Error: Unexpected token (11:7)

This problem arises in the default project structure generated by running:

vue init Toilal/vue-webpack-template my-project

The specific code causing the error is as follows:

@Component
export default class HelloWorld extends Vue {

  @Prop({ default: 'default ToDo' })
  todo: string; // unexpected token

  name = "test9"; // works fine
}

All other aspects of the project seem to be functioning correctly, and my search for a solution did not reveal any instances where ':' was flagged as an unexpected token. One individual faced a similar issue around two years ago and resolved it by updating their npm version, although I am already using a much newer version.

Here are the dependency sections from my package.json. Could the problem stem from an incompatible combination of libraries?

"dependencies": {
  "vue": "^2.5.2",
  "vue-class-component": "^6.0.0",
  "vue-property-decorator": "^6.0.0"
},
"devDependencies": {
  // List of dev dependencies
}

Answer №1

Ensure that TypeScript is declared within the script element

<script lang="ts">
    ...
</script>

Answer №2

default is a reserved term in Vue; consider using an alternate keyword. In JavaScript, it is typically utilized within switch cases to provide a fallback option or for exporting data.

Answer №3

Enclose default with double quotation marks:

@Prop({ <strong>"default"</strong>: 'default ToDo' })

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

Replicating divs in Vue with ease

<template> <b-form @submit.prevent="Submit" class="mb-5"> <div class="inputArea" v-for="input in inputs" :key="input.id"> <b-form-group label-cols-sm="2" l ...

Are there any available NPM packages specifically for integrating with QuestDB?

Just started using QuestDB and I'm curious if there is an npm package available for it. I found a package on npmjs.com/questdb, but it appears to be empty. Can someone confirm if there is indeed an npm package for QuestDB? Thank you! ...

How can one retrieve the selected value from a dropdown menu in Angular?

Objective: My goal is to create a dropdown menu where users can select a value, which will then dynamically change the address of the website based on their selection. Issue: Although I managed to make the address change upon selection, it did so for ever ...

dynamically import a variety of components in vue.js and nuxt depending on certain conditions

Is there a way to implement dynamic imports for all 3 components in this scenario? Each component has different props, so using the switch option in the computed method is not feasible. I have come across solutions for using a single component dynamically ...

Can you explain how to utilize multiple spread props within a React component?

I'm currently working in TypeScript and I have a situation where I need to pass two objects as props to my React component. Through my research, I found out that I can do this by writing: <MyComponent {...obj1} {...obj2} /> However, I'm fa ...

What is the best way to import a Vue.js component using the @/xxxx/component.vue file path?

I am attempting to implement a Vue.js template called Core-UI with Laravel, but I am encountering an issue with this file. When I compile it, I receive the following error: These dependencies were not found: * @/containers/DefaultContainer in ./resources ...

Ways to format a DataTable row for increased height when there are over 20 columns

I'm working with a DataTable and trying to figure out how to display the rows in a way that utilizes multiple row spaces when the number of columns exceeds 20. I attempted using custom CSS, but it doesn't seem to be working properly. Currently, I ...

The view named 'HelloWorld' could not be found within the servlet named 'dispatcherServlet'

I have recently started learning Spring Boot. My goal is to display an HTML page, but unfortunately I am facing some issues. When I change HelloWorld.html to HelloWorld.ftl, I am able to display the FTL page. However, the vue.js file is not being resolve ...

Encountered a problem while creating a new Angular 7 app: Module 'temp' not found

While attempting to create a new app using the command ng new first-app, I encountered the following error: internal/modules/cjs/loader.js:589 throw err; ^ Error: Cannot find module 'temp' at Function.Module._resolveFilename (internal ...

Executing npm install gets stuck just like running npm install with the --verbose flag

I started off with a basic Ionic application that I cloned from a git repository. However, when I tried to install npm, it got stuck at the "loadAllDepsIntoIdealTree" stage. After some research, I came across a solution mentioned here: https://github.com/n ...

When running jest unit tests, an error is thrown stating that includes() and toLowerCase are not functions

MyComponent.js contains both toLowerCase and includes methods on the props. However, when attempting to perform unit testing on MyComponent, I encounter an issue where the functions toLowerCase() and includes() are not recognized as valid. Within MyCompon ...

What is the process of developing a straightforward Node.js script to encapsulate a binary or executable file?

I am looking to develop a Node.js file that can seamlessly execute an executable binary file and handle all inputs and outputs, specifically targeting Windows operating systems. Reason for this: I aim to install an executable tool via npm install -g in or ...

Enhancing Material UI v4 Themes using TypeScript

I am attempting to implement my own custom palette option in the theme section, but I am struggling with how to do the augmentation part using TypeScript. So far, I have created a file named "material-ui.d.ts" and inside it, I only have: import { PaletteO ...

Determine if a mobile application has been installed using Vue.js

I am currently developing a web application and have implemented a check to determine whether the user is accessing it from a mobile device or laptop. Let's consider the link as: my-site.com In addition to the web version, my site also offers a mobi ...

Ways to attain a similar format - input map

After pressing the save button, I am aiming to achieve the following effect: "timeTable":{ "0": [{"from":"08:00","to":"12:00"}, {"from":"14:00","to":"18:20&q ...

Having issues with an Android app crashing on Android 12+ devices when receiving push notifications in the background. This problem is occurring with an

An error occurred with the Firebase-FCMService while running the app. The specific process and PID are as follows: com.petbacker.android, 4405. This issue is related to an IllegalArgumentException stating that targeting S+ (version 31 and above) requires e ...

Use contextual type when determining the return type of a function, rather than relying solely on

When using Typescript 2.2.2 (with the strictNullChecks option set to true), I encountered an unexpected behavior. Is this a bug or intentional? interface Fn { (value: any): number; } var example1: Fn = function(value) { if (value === -1) { ...

Upon refreshing, the page displays a message stating that the resource being sought has been removed, its name has been altered, or it is currently inaccessible

For my project, I decided to deploy a Nuxt 3 website as a classic SPA without the need for SSR. I used nuxt generate and deployed the contents from .output/public/ in an Azure static web app. Everything is up and running smoothly, but I encountered an issu ...

A guide to resolving the error "Unable to find 'require' in vuejs"

I am currently working on a project using vuejs and firebase. I encountered an issue while trying to import firestore. When I accessed my page, I saw this error message in the console: ReferenceError: require is not defined I attempted to place the import ...

Vue-Router: Moving to a nested state or route based on their name and parameters

How do I use $router.push to navigate to a child state? This is my current route configuration: const routes = [ { path: "/customers", name: 'Customers', components: {content: CustomersMain}, props: {header: true, content: false}, ...