When I utilize nuxt alongside TypeScript in conjunction with koa and execute the "dev" command, the terminal alerts me of compilation issues within Vue files that incorporate TypeScript syntax

  • nuxt: 2.6.2
  • node: 16.5.0
  • koa: 2.7.0

Here is the content of my package.json file :

{
    ...
    "scripts": {
        "dev": "cross-env NODE_ENV=development nodemon server/index.ts --watch server --exec babel-node --presets @babel/preset-env"
    }
}

Observations:

Upon running the command `yarn dev`, the following events unfold:

  • The KOA server successfully compiles and runs, prompting me with the question "Are you interested in participating?". I select "yes".

  • Subsequently, as the Nuxt web server begins to compile, an error message stating "ERROR Failed to compile with 3 errors" appears on the console. Upon investigation, it becomes evident that these errors are related to TypeScript usage within my Vue pages or Components, such as:

Module parse failed: Unexpected character '@' (11:0)                                                                                                                                                                                                           friendly-errors 23:08:49
File was processed with these loaders:
 * ./node_modules/vue-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
| import {Vue, Component} from 'vue-property-decorator';
|
> @Component
| export default class GlobalLayout extends Vue {
|
                                                                                                                                                                                                                                                               friendly-errors 23:08:49
 @ ./layouts/GlobalLayout.vue?vue&type=script&lang=ts& 1:0-124 1:140-143 1:145-266 1:145-266
 @ ./layouts/GlobalLayout.vue
 @ ./.nuxt/App.js
 @ ./.nuxt/index.js
 @ ./.nuxt/client.js
 @ multi ./node_modules/eventsource-polyfill/dist/browserify-eventsource.js (webpack)-hot-middleware/client.js?reload=true&timeout=30000&ansiColors=&overlayStyles=&path=%2F__webpack_hmr%2Fclient&name=client ./.nuxt/client.js
  • Eventually, the console is able to display the output of console.log statements written in `server/index.ts`. This raises the question whether using `nodemon` instead of `nuxt` to start the entire server could potentially resolve some of the TypeScript compilation errors encountered. Surprisingly, running `nuxt` directly results in successful compilation without any errors, whereas integrating Koa and modifying the development command leads to these issues.

Exploring Solutions

In an attempt to address this issue, I searched for a similar repository online and stumbled upon one that utilizes nuxt + ts + koa in a manner akin to mine.

Sample Code Repository

https://github.com/negibouze/nuxt-koa-ts

I cloned this repository and reproduced the same errors on my local machine. Feel free to clone and investigate further.

Answer №1

TS seems to need an extra component in order to function properly.
I took the sample project and replicated it, ensuring I installed all necessary packages and also globally installed them:

After completing these steps, everything ran smoothly.

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

Display or conceal HTML content based on the input's property type

Looking to toggle the visibility of an icon on my input based on the prop type. If the type is set to password, the icon will be displayed for toggling between visible and hidden password; if the type is not password, the icon should be hidden by setting ...

What is the best way to retrieve the current path in the app's directory using Next.js?

Exploring the new features of the experimental app folder in Next.js 13, I encountered a change where next/router has been replaced with next/navigation. As a result, I adjusted my code to import the useRouter hook. However, I noticed that the property pat ...

Why is it that the changes I make in the parent component do not reflect in my Angular component?

As I embarked on creating a custom select component, I began with the input below: @Input() options: SelectOption<UserRole>[] = []; The parent component (user editor) utilizes this select component and provides the options as shown below: roleOption ...

Guide to accessing and modifying attributes of Ionic components in TypeScript file

I am curious about how to manipulate the properties or attributes of an Ionic component from a TypeScript file. For example, if I have an input component on my HTML page: <ion-item> <ion-input type="text" [(ngModel)]="testText"></ion ...

What is the best way to configure Jenkins to exclude or include specific component.spec.ts files from being executed during the build

Currently, I am facing an issue while attempting to include my spec.ts files in sonarqube for code coverage analysis. However, my Jenkins build is failing due to specific spec.ts files. Is there a way to exclude these particular spec.ts files and include ...

Angular 6's Select feature is failing to properly update user information

We are currently facing an issue with our user profile edit form. When users try to update their information by changing simple input fields, the changes are reflected successfully. However, when they make selections in dropdown menus, the values do not ge ...

I am eager to retrieve every single item within the categories section utilizing a Vue component

Below is my Vue component CreateProduct.vue <template> <div> <div class="row mb-4"> <label for="category" class="col-md-4 col-form-label text-md-end">Category</label> ...

Utilize Vue.js to incorporate an external JavaScript file into your project

Currently, I am utilizing Vue.js 2.0 and facing an issue with referencing an external JavaScript file in my project. The index.html file contains the following script: <script type='text/javascript' src='https://d1bxh8uas1mnw7.cloudfro ...

Utilizing Angular HttpClient and Observable to map foreign keys to data models

Imagine having a scenario where there are mothers and children entities, with the mother holding a foreign key linked to the child's ID. The challenge arises when the API can only retrieve all mothers and children from separate endpoints, resulting in ...

What is the method to utilize dynamically generated computed properties in v-model in Vue?

I have a dataset structured like this: const entries = ref([{scopes: ["a", "b"]}]) Within my Vue template, I need to iterate through each entry in entries and generate an input box for the scopes field. To achieve this, I created the following helper func ...

A guide to incorporating Material-UI ThemeProvider and WithStyles with Typescript

I've been feeling frustrated lately as I've been dedicating the past few days to migrating my React application from JavaScript to TSX. While I appreciate the type checking that TSX provides, I'm struggling with understanding how to implemen ...

Connecting data to a file input's value: A guide on binding in HTML

I have successfully retrieved data for objects from an API and now need to display it in an input field so I can edit it later. I have managed to achieve this with text values using v-model. However, I am unsure of how to display the file name that is be ...

Component triggering a dirty state in Vue

On my Vue page, I have input fields and would like to display a message when any of these input fields are changed. In Angular, this can be done easily with the isDirty function, but in Vue, this functionality is not available. Is there a method to captur ...

Every time I try to deploy my app on Heroku, it keeps crashing with a strange error popping up on the home screen

Here are the logs for my application: 2018-07-19T01:40:27.548845+00:00 app[web.1]: at Object.<anonymous> (/app/node_modules/bcrypt/bcrypt.js:6:16) 2018-07-19T01:40:27.548847+00:00 app[web.1]: at Module._compile (module.js:652:30) 2018-07-19T01:40:27 ...

Creating a TypeScript interface for Immutable.js objects: A step-by-step guide

Imagine we are working with the following interface User: interface User { id: number; name: string; bag: Item[]; } Now, let's create a React component: interface UserComponentProps { user: User; } interface UserComponentState {} class Use ...

Combining Firebase analytics with an Ionic 3 application using the Ionic Native plugin

I placed the GoogleService-Info.plist file at the root of the app folder, not in the platforms/ios/ directory. When I tried to build the app in Xcode, an error occurred in the following file: FirebaseAnalyticsPlugin.m: [FIROptions defaultOptions].deepLin ...

Malfunction of VueJS single-page application on WordPress admin menu page

The VueJS project was created using the Webpack template in vue-cli. When building for production, a static folder is generated with 2 subfolders and an index.html file. The subfolders include css and js, with one css file and three javascript files - app. ...

Vue 3 - Cascading Property Updates throughout the Component Tree

I have a Vue 3 application set up in the following structure: +---------------------+ | Component | | +-----------------+ | | | Child Component | | | +-----------------+ | +---------------------+ The components are structured as follows: my-com ...

Strategies for troubleshooting a blank page issue when launching a secondary Vue application with nginx

I am looking to run multiple Vue.js v3 apps with nginx on macOS Big Sur. The first app is located at: /Users/kharraz/Developer/code/homeapp/dist; And the second app is located at: /Users/kharraz/Developer/code/businessapp/dist; Both folders contain outpu ...

Error in Angular: Unable to bind FormControl to input due to unexpected issue

I need help resolving a common error I'm encountering. I have forms in two different sections of my application, and while the form functions correctly in one section, it is not working in the other. Both ReactiveFormsModule and FormsModule are import ...