Vue.js: The $attrs and $listeners properties are both read-only

I attempted to construct my own component library using Vuetify, utilizing vue-cli vue create d-components. I registered my components through an install function that was exported in the main.ts file of my library like this:

import Vue, { VueConstructor } from 'vue';
import Vuetify from 'vuetify';
import DBtn from "./components/DBtn.vue";

Vue.use(Vuetify)

export default {
  install(vue: VueConstructor): void {
    vue.component("d-btn", DBtn);
    ...
  }
}

One of the components is defined as follows:

<template>
  <v-btn v-bind="$attrs" v-on="$listeners" elevation="0" small>
    ...
  </v-btn>
</template>

<script lang="ts">
import { Component, Vue } from "vue-property-decorator";

@Component({})
export default class DBtn extends Vue {}
</script>

I included this library as a git submodule in my primary Vue.js application (which also uses Vuetify), performed npm install, and ran npm link in the root folder of the submodule, then executed npm link d-components in my main Application directory.

My application imports & calls the install function of my library like this:

import Vue from 'vue';
import DComponents from "d-components" // name of the library

Vue.use(DComponents);

Everything appears to be functioning correctly so far.

However, when attempting to use the components from my library, a series of errors are generated:

[Vue warn]: $attrs is readonly.

[Vue warn]: $listeners is readonly.

It appears that this issue arises due to the creation of two instances of Vue within my application. I have checked to ensure that all my imports of Vue are consistent, but I only found import Vue from 'vue' in both my main application and my library.

Does anyone have any suggestions on how to verify whether multiple instances of Vue are being created?

Answer №1

A potential issue could be arising from a duplicate Vue instance, which may not have been flagged in your console as a warning.

This duplication may stem from using 'npm link' within a submodule, causing the submodule package to be installed globally along with all of its dependencies, including Vue. To verify this, check the node_modules directory of your globally installed submodule - you should find a copy of Vue there.

To resolve this, consider utilizing 'npm link ../component' (instead of running npm install in the component directory) from your project directory, or alternatively, publish the component via 'npm publish' and install it as a regular dependency for your project. This approach will prevent the secondary installation of Vue in the node_modules directory of your component.

Answer №2

In my situation, I discovered that the duplicate instances were caused by certain Vue plugins importing the Vue instance in a different way than specified in my project. To solve this issue, I made adjustments to my Webpack configuration by adding the following code:

    externals: {
      // Overrides `require('vue')` to return `global.Vue`
      vue: 'Vue',
    },

I hope this solution proves useful for anyone facing the same problem :)

Answer №3

This issue arises when Vue is imported multiple times within your code. Therefore, it is important to specify the correct path.

For users of Vue 2.7 and Vite, consider using the following code:

Import the path module:

import path from 'path';

Add the following configuration in your settings:

resolve: {
  alias: {
     vue: path.resolve(__dirname, './node_modules/vue/dist/vue.esm.js'),
  },
}

Answer №4

$vuetify is a necessary package for using the Vuetify framework.

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

No versions for "cra-template-typescript" that align with "latest" were located in our cache

Currently attempting to follow the steps outlined in this helpful guide: How to Develop a Basic React Application With an Express API. However, upon executing the command: npx create-react-app react-express-app --template typescript I encountered the foll ...

The error message "Property 'list' is not found on type 'void' React - Material UI" indicates that the 'list' property is not recognized

Currently, I am facing an issue while working with Material UI and React Typescript. The error message I receive is "Property 'list' does not exist on type 'void'" when attempting to use makeStyles and createStyles to remove padding. It ...

Vuex state disappears after token reaction

Fetching the value of the username field from a JWT in a DRF response using VueJs is causing some issues for me. I have initialized my state within a vuex module: function initialState() { return { accessKey: null, refreshKey: null, username ...

Is there a program available that can efficiently convert or translate JSON objects into TypeScript types or interfaces?

Can anyone recommend a tool that can easily convert a JSON object into a TypeScript type or interface? An example input would be something like this: I'm hoping to paste the JSON object into the tool and receive an output structure similar to: expor ...

Integrate an additional filter into vue-table-2

Looking for assistance on integrating an external filter into vue-table-2. I've attempted using slots, but haven't had success. <div slot="filter__id"> <input type="input" class="form-control"> </d ...

What is the best way to adjust and filter an array based on a single value?

Here is an array that needs to be modified: [ {name: "test", value: "test", group: 0}, {name: "test1", value: "test2", group: 0}, {name: "test3", value: "test3", group: 1}, {name: "te ...

Understanding the Matching Behavior of Vue Router Paths

Take a look at the code provided in this Code Sandbox: https://codesandbox.io/p/sandbox/vue-router-playground-forked-2rg2n8?file=%2Fsrc%2Frouter.js%3A17%2C51 Things to note: After clicking on the go to users link within the application, the route's ...

Create collaborative documents with serverless TypeScript extension

Utilizing Amazon Lambda AWS along with Serverless and the Serverless Plugin TypeScript to develop my TypeScript files has been quite a challenge. I have implemented shared code in my project, organized within folders such as: /shared: shared1.ts, shared2. ...

Tailor TypeScript to support various JavaScript versions

One of the advantages of TypeScript is the ability to target different versions of Javascript globally - allowing for seamless switching between transpiling ES3, ES5, or ES6. For browsers like IE that require ES3 support, it serves as the lowest common de ...

Check if the date is valid and falls after the current date using the v-validate directive

How can I validate a datetime field in my form? <datetime v-validate="'before:2016-05-25|date_format:yyyy-MM-dd|required'" format="YYYY-MM-DD" name="DateTime" width="100px" id="DateTime" :class ...

Top Tips in Angular2 for showing buttons depending on a user's security authorizations

I’m in the process of building my inaugural Angular 2 website. Featuring a Bootstrap NavBar positioned on the left side, users can effortlessly navigate to various pages within the site. The navigation buttons displayed on the NavBar are tailored based o ...

Exploring the structure of TypeScript types using the Compiler API

Is there a way to extract specific type information directly from the TypeScript compiler using an API method? Here's an example: interface User { id: number name: string } type NameOnly = Pick<User, 'name'> type NameOnlyAliased ...

When utilizing custom ngDoBootstrap and createCustomElement in Angular, the router fails to recognize the URL being used

WHEN I implement a custom ngDoBootstrap function instead of the default bootstrap: [AppComponent] like shown below: @NgModule({ imports: [ BrowserModule, FormsModule, AppRoutingModule ], declarations: [ AppComponent, HelloComponent ], exports: ...

How should I properly initialize my numeric variable in Vue.js 3?

Encountering an issue with Vue 3 where the error message reads: Type 'null' is not assignable to type 'number'. The problematic code snippet looks like this: interface ComponentState { heroSelected: number; } export default define ...

How can I style and manipulate an array in Vue.js to only show the active element?

I have an array of cards with buttons on each card. When I click a button, all buttons change their style. How can I apply the style to only the active button and not all buttons? <template> <div> <div v-for="i in cards" id= ...

Extra assistance might be required to manage the output from these loaders

I'm in the process of developing a State Management Library for ReactJs. However, when I integrate it into my React project (built with create-react-app), an error is thrown: Failed to compile. path/to/agile/dist/runtime.js 116:104 Module parse faile ...

How can I turn off strict null checks in TypeScript when using ESLint?

ESLint keeps flagging my object as potentially null despite having an if statement to check for it. const user: User | null = getUser() if (user) { // if (user !== null) doesn't work either await user.updateProfile({ di ...

Error: Unable to access 'isCE' property of null - Custom Component Library

Struggling to create a custom component library for Vue 3 using ViteJS and NPM. Here is a breakdown of my setup, can someone guide me in the right direction as I have hit a roadblock for the past couple of days. Here's how my files are structured: d ...

Having trouble accessing property '0' of undefined in angular

Below is the code I am currently working on. My goal is to enable editing of the table upon click, but I encountered the error mentioned below. Could someone kindly explain why this is happening and suggest a workaround? <tbody> <tr *ngFor="l ...

Using JavaScript, generate an array of objects that contain unique values by incrementing each value by 1

I have an array of objects called arrlist and a parameter uid If the property value has duplicate values (ignoring null) and the id is not the same as the uid, then autoincrement the value until there are no more duplicate values. How can I achieve the a ...