Encountering a Vueify Typescript error in a Vue project

Recently diving into the world of Vue, I was able to successfully create a sample app using gulp, vueify, and TypeScript. To showcase what's happening and shed light on an issue I'm facing, here are snippets of the key code segments:

Menu.ts

import Vue from 'vue'
import Menu from './menucomponent.vue'
new Menu().$mount('#menu');

MenuComponent.ts

import { Vue } from 'vue-property-decorator'
import Component from 'vue-class-component'
import TestComponent from './test.vue'

@Component({
    components: {
        TestComponent 
    }
})
export default class Menu extends Vue {}

MenuComponent.vue

<template>
    <div class="container menu">
    <TestComponent/>
    </div>
</template>
<script lang="ts" src="./menucomponent.ts"></script>

Test.vue

<template>
<h1>hi</h1>
</template>
<script lang="ts">
import { Component,Vue } from 'vue-property-decorator'
@Component({
})
export default class test extends Vue{}
</script>

Gulp method for compiling TypeScript and Vue files

gulp.task('compile-vue', function () {
    var paths = {
        browserifyEntries: [
            'menu.ts'
        ],
        dependencies: ['']
    };
    
    var tasks = paths.browserifyEntries.map(function (entry) {
        console.log('Compiling ' + entry);
        return browserify({ entries: ["ScriptsSrc/vue/" + entry] })
            .external(paths.dependencies)
            .plugin(tsify)
            .transform(vueify)
            .transform(babelify, { presets: ["es2015"], extensions: [".tsx", ".ts"] })
            .bundle().on('error', swallowError)
            .pipe(source(entry))
            .pipe(rename({
                extname: '.js'
            }))
            .pipe(gulp.dest('wwwroot/scripts'));
    });
    return es.merge.apply(null, tasks);
});

Challenge While everything runs smoothly in MenuComponent, when attempting to split it into components like ``, Vue throws an error:

[Vue warn]: Unknown custom element: - did you register the component correctly? For recursive components, make sure to provide the "name" option.

I stick with using only gulp in my build process to avoid webpack. Any insights on what could be causing this issue would be greatly appreciated.

Answer №1

It seems like the issue lies in the naming of the class in Test.vue and the corresponding import statement in MenuComponent.ts.

Consider updating the class name to:

export default class TestComponent extends Vue{}

This change should coincide with the expected exported default in the import statement:

import TestComponent from './test.vue'

Alternatively, you can modify the import statement to:

import test from './test.vue'

Additionally, make sure to adjust the component registration as follows:

components: {
    test
}

Answer №2

If you're struggling with TypeScript, Vue, and Gulp, the solution I found after many hours might be helpful to you.

Here's the modified code that seems to work for now:

Menu.ts

import Vue from 'vue'
import Menu from './menucomponent.vue'
import TestComponent from './test.vue'
new Menu({components:{TestComponent}}).$mount('#menu');

It appears that injecting the component at this level eliminates the need for @Component() in MenuComponent.

While there may be a simpler way to register the component inside MenuComponent, this workaround serves its purpose for now.

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

There are no HTTP methods being exported in this specific file. Remember to export a named export for each individual HTTP method

Currently, I am working on a React.js/Next.js project that incorporates Google reCAPTCHA. The frontend appears to be functioning properly as I have implemented print statements throughout the code. However, I am encountering an error in the backend display ...

Creating custom components that encapsulate the functionality of Angular Material tabs component

I am aiming to incorporate the Angular Material tabs component within my shared components. Here is the component I'm attempting to wrap: Note: Each tab can display a component: <mat-tab-group> <mat-tab label="First"> Content ...

Creating an instance of a class using a class decorator, with or without the 'new'

Seeking alternatives to creating class instances without using the new keyword in TypeScript, I came across this excellent solution that works seamlessly in JavaScript. The code found in the repository mentioned https://github.com/digital-flowers/classy- ...

What could be the reason behind the Vue property being globally undefined in the component at the time of mounting?

Creating a custom Vue plugin was essential for me, which establishes a global property on Vue in this way: function (Vue, options) { Vue.$detector = new TranslatableStringDetector(); } Utilizing it within a computed property in my component is done l ...

Is there a way to set up TS so that it doesn't transpile when an error occurs?

Is there a way to configure my tsconfig.json file in order to prevent transpiling if an error occurs? I have searched the documentation but couldn't find any flag or configuration for this. Does anyone know how I can achieve this? ...

Unable to include item in an array

I have an issue with populating my breadcrumb array as I navigate through my category tree. Despite adding elements to the array, they are not displaying - even when I use console.log("bread", Array.from(this.breadcrumbs)), they only show up in ...

What is the best way to include arrays in VueJS?

Currently, I am working with two arrays in my Vue application. The first array called desserts lists all the desserts that I have. The second array, moreDesserts, displays checkboxes with values. When a user selects a checkbox, the value is added to the se ...

Unlocking the Power of Dependent Types in TypeScript: Unveiling Type by Property Name Declaration

In an attempt to tie the types to the arguments passed, consider the following example: type NS = "num" | "str" type Data<T extends NS> = T extends "num" ? number : string type Func<T extends NS> = (x: Data<T> ...

After clicking on the "Delete Rows" button in the table, a white color suddenly fills the background in Angular Material

When the dialog box pops up, you'll see a white background color: https://i.stack.imgur.com/EflOx.png The TypeScript code for this action can be found in config-referrals.component.ts openDialog(action, obj) { this.globalService.configA ...

Utilizing Vuex, is it possible to filter an array by incorporating another array in a Javascript view?

When using VueX, I am attempting to filter my "ListJobs" array based on the currentTag. Essentially, I want to return elements that match any of the values in the currentTag array with the rows role, level, languages, and tools. state: [ listJobs: ...

"Exploring the world of Typescript with the Drawflow library

Currently, I am integrating the fantastic Drawflow library created by @Jerosoler (available at: https://github.com/jerosoler/Drawflow) into my PrimeNg project. User @BobBDE has provided typescript definitions for this library here: https://www.npmjs.com/p ...

Wait for a minimum of X milliseconds using RxJS

I'm attempting to achieve a specific functionality using RxJS: Trigger an event Make an API call Upon receiving the API response, do one of the following: Wait for at least X milliseconds after triggering the event If X milliseconds have already p ...

Error: Unable to inject UrlHandlingStrategy as no provider was found

I recently upgraded my application to Angular 14 and encountered a challenging error. Despite configuring RouterModule for Root and child with lazy loading, I am now facing a circular dependency issue related to the Router. I'm unsure how to further d ...

Exploring Polymorphism in Typescript through Data Model Interfaces

Seeking out a design pattern for the following scenario: IApp.ts export interface IApp { platform: PlatformEnum; version: string; islive: boolean; title: string; iconurl: string; } IAppleApp.ts export interface IAppleApp extends IApp { ...

Ways to verify the authenticity of a JWT token

I recently came across a tutorial on creating user authentication with Vue.js and Lumen. The tutorial utilizes the tymon/jwt-auth library to handle authentication. So far, everything is working smoothly. The API manages all my data and provides a token to ...

Executing Promises in a loop: TypeScript & Angular with IndexedDB

Currently, I am working on a data synchronization service where data is being retrieved from a web service and then stored in IndexedDB. In my TypeScript Angular Service, the code looks something like this: this.http .post(postUrl, postData) .suc ...

Guidelines for creating a binary release of Node.js with native modules

Currently, I am in the midst of exploring the world of Node.js projects, delving into different bundlers and various other components. One interesting concept that came to mind is the idea of bundling Node.js into a single binary for Linux, macOS, or Windo ...

Property element does not exist in this basic TypeScript project

I'm diving into my initial TypeScript project and encountering an issue with the "style". I attempted to utilize style!, create an if(changeBackgroundColor){}, but without success. let changeBackgroundColor = document.querySelectorAll('[data-styl ...

What exactly is an npm "modular construction" and what is the process for setting it up?

I am aiming to integrate sortablejs's MultiDrag feature with Vuejs2 and Typescript. The official documentation states: MultiDrag is a plugin for SortableJS, but it may not be included in all of Sortable's builds. It comes pre-installed in the ...

Exploring Improved Methods for Implementing Nested Subscriptions in Typescript

In my Typescript code for Angular 11, I am working with two observables. The first one, getSelfPurchases(), returns data objects containing information like id, user_id, script_id, and pp_id. On the other hand, the second observable, getScriptDetails(32), ...