Ways to bring in a Typescript Vue project to a Javascript Vue

I am trying to incorporate this Calendar component into my Javascript Vue 3 project. To achieve this, I have created a new component in my project named ProCalendar.vue and copied the code from the example found in App.vue. Additionally, I have added the necessary dependency in the main.js file.

However, upon setting up the calendar component, I encountered several errors when running npm run dev:

INFO  Starting development server...


 ERROR  Failed to compile with 3 errors                                                                                  19:54:20

[eslint]
C:\Users\chuan\Documents\GitHub\PraePlan\services\frontend\src\main_components\home_components\ProCalendar.vue
  3:19  error  Parsing error: Unexpected token, expected "," (3:19)

✖ 1 problem (1 error, 0 warnings)


You may use special comments to disable some warnings.
Use // eslint-disable-next-line to ignore the next line.
Use /* eslint-disable */ to ignore all warnings in a file.
 error  in ./src/main_components/home_components/ProCalendar.vue?vue&type=script&setup=true&lang=ts

Module parse failed: Unexpected token (3:19)
File was processed with these loaders:
 * ./node_modules/vue-loader/dist/index.js
You may need an additional loader to handle the result of these loaders.
| import { defineComponent as _defineComponent } from 'vue'
| import "vue-pro-calendar/style";
> import { ref, type Ref } from "vue";
| import type { Configs, Appointment } from "vue-pro-calendar";
|

... (error continued)

<p>Upon researching, I learned that the issue might be related to the absence of TypeScript in my project. As a result, I tried installing TypeScript using <code>npm install typescript and npm install ts-loader, but it did not resolve the errors.

Below is a snippet of my package.json for reference:

{
  "name": "praeplan",
  ...
}

The content of my ProCalendar.vue file (copied from the GitHub project) is displayed below:

<script setup lang="ts">
import "vue-pro-calendar/style";
import { ref, type Ref } from "vue";
...

</script>

<template>
...

And here's how my main.js file looks like:

import { createApp } from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import { ProCalendar } from "vue-pro-calendar" 

createApp(App).use(store).use(router).use(ProCalendar).mount("#app");

Any assistance or guidance on resolving these errors would be greatly appreciated! :)

Answer №1

Estus Flask makes a valid point in his response. If you eliminate all TypeScript-related code, there is no need to install TypeScript. Your revised script should resemble the following:

<script setup>
import "vue-pro-calendar/style";
import { ref } from "vue";

const config = ref({
  viewEvent: undefined,
  reportEvent: {
    icon: true,
    text: "",
  },
  searchPlaceholder: "",
  eventName: "",
  closeText: "",
  nativeDatepicker: true,
});

const events = ref([
  {
    date: "2022-11-19T14:00:00.000Z",
    comment: "",
    id: "cl32rbkjk1700101o53e3e3uhn",
    keywords: "Projet BAMBA",
    name: "MONTCHO Kévin",
  },
  //...
]);
</script>

I conducted my own test and validation on this StackBlitz platform to confirm that the library functions effectively as a JavaScript 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

Encountering problems while trying to install Bower

I'm having trouble with installing bower correctly. Whenever I try, it keeps giving me these errors. Can anyone provide some guidance or assistance? npm ERR! tar.unpack untar error /Users/Jeanwoo/.npm/bower/1.4.1/package.tgz npm ERR! Darwin 14.0.0 np ...

Having trouble with installing discord.js in Visual Studio Code

Being new to programming, I am struggling to grasp concepts related to node.js and other similar technologies. My current challenge lies in installing discord.js within Visual Studio Code. Despite attempting the command "npm install discord.js" in both th ...

Encountering an issue with WebRTC where the 'addIceCandidate' function on RTCPeerConnection is failing, resulting in an error displayed on the console. However, despite this error

I am facing an issue with connecting two peers using webRTC. While I can successfully display both local and remote videos, as soon as the remote video appears, the candidate object turns null and an error message is logged on the console. TypeError: Fail ...

Ways to use string functions in JavaScript to substitute with /

Here is the image path I am working with: var str = "D:\Poc\testProject\DataPush\public\unzip\cust\AccountData\2.jpg" When I included "unzip" in the path, it threw an error as shown in this image, but when ...

ERROR: program closure detected with one task still in progress

Currently, I am in the process of developing end-to-end tests for an Angular application. One of the steps before running my test suites is to manually start the backend (.NET application) - which prompted me to think about automating this process. During ...

Learn how to effortlessly download a file from Amazon S3 using Angular and ng-click technology

When attempting to download a file from my Amazon S3 bucket using Angular's ng-click, I am receiving a blank file instead of the expected content. HTML <div class="details-field"> RC Book <font class="digit" >({{rcCount}})</font> ...

Axios - Show the error message returned from validation as [object Object]

Within my API, I include the following validation logic: $request->validate([ 'firstname' => 'required', 'lastname' => 'required', 'username' => 'required|unique:us ...

Effective ways to resolve the ajax problem of not appearing in the console

I am facing an issue with my simple ajax call in a Java spring boot application. The call is made to a controller method and the returned value should be displayed in the front-end console. However, after running the code, it shows a status of 400 but noth ...

Incorporating DefinitelyTyped files into an Angular 2 project: A step-by-step guide

I am currently developing an application using angular 2 and node.js. My current task involves installing typings for the project. In the past, when starting the server and activating the TypeScript compiler, I would encounter a log with various errors rel ...

React App anchor tag's external links fail to function properly on subsequent clicks when accessed through mobile devices

I have encountered an unusual issue with <a> anchors for external links in my React App on mobile viewports. Initially, clicking an external link opens a new tab just fine on mobile. However, subsequent link clicks on the same or other <a> elem ...

During the initial render in next-auth, the useSuspenseQuery function is triggered to fetch data without a defined token, resulting in an

Recently, I've started implementing the new useSuspenseQuery feature from react-query and I couldn't help but notice that the enabled property is missing on this hook. This has caused an issue with my useGetApiToken function, as it initially retu ...

Display Angular errors specifically when the input field is filled out and contains invalid data

I need help with toggling an error area on my form so that it only appears once there is input. It seems unnecessary for errors to show up if the user hasn't even started typing. <form name="registerForm"> <input type="email" name="email" ...

What is the best way to connect to a library using a script within a Typescript React application?

I'm a newbie to React and haven't worked on web development in years, so I'm facing a basic issue: Currently, I'm working on implementing a Stripe-based payment flow in a React web app (written in Typescript) and I've hit a roadbl ...

Using JavaScript to dynamically retrieve element IDs

Within the content on my page, there are multiple tables displaying product information along with their respective authors. Additionally, there is a div that contains hyperlinks for each author. Currently, I am linking the authors' names to hyperlink ...

Universal capability for selecting all items in a table

Here we have a snippet of code from my grid (CRUD) component: <template> <table class="MyComponent table"> <thead> <tr> <th width="30px"> <b-form-checkbox v-model="allC ...

Inquiry regarding the ng-disabled directive in AngularJS

<div ng-app="myApp" ng-controller="myCtrl"> <button type="submit" class="btn btn-primary pull-left" ng- disabled="captchaError">Submit</button> </div> <script> var app = angular.module('myApp', []); app.controller( ...

Change the text color of the Vuetify button to customize its appearance

Is there a way to change the default active color for button text in a toolbar using CSS? v-btn(:to="item.path" active-class="v-btn--active toolbar-btn-active") {{item.meta.title}} I attempted to override it with this custom class: .toolbar-btn-active { ...

Adding options to a dropdown menu dynamically while editing a form with the help of javascript

I have a dropdown like in below:- <form name="depositForm" action="<?php echo site_url('ajax_funds/deposit_funds'); ?>" id="depositForm" class="page-form-main form-horizontal " autocomplete="off" method="post"> <div class="form- ...

I encountered an issue with the onclick event in JavaScript

I have been struggling with an issue for some time now and I just can't seem to figure out what I am doing wrong. Here's the problem - when I click on a link on my website, a calculator should pop up. Then, when I click the off button on the calc ...

Verifying Content in JavaScript

Here is a snippet of code I used to validate a Registration form on a content page. However, the validation part seems to not be functioning properly. Any assistance would be greatly appreciated. Master Page <%@ Master Language="C#" AutoEventWireup="t ...