Importing a third party vue component inside an npm package - vuejs2

I am developing an npm package. And I use third party library components inside my package. But I am having trouble importing components inside a package. For example with https://github.com/rlemaigre/Easy-DnD:
My CustomPackageComponent.vue:
<template>
<div>
<drop-list :items="[1, 2]">
<template v-slot:item="{item}">
<drag :key="item">
{{ item }}
</drag>
</template>
</drop-list>
</div>
</template>
<script>
import Vue from "vue";
import {DropList, Drag} from "vue-easy-dnd";
export default {
data() {
return {
someVar: 'foo'
}
},
components: {DropList, Drag}
}
</script>
And next in my index.js file:
import CustomPackageComponent from './components/CustomPackageComponent'
export {
CustomPackageComponent
}
Finally I use in my app. SomeAppComponent.vue:
<template>
<div>
<custom-package-component/>
</div>
</template>
<script>
import {CustomPackageComponent} from '#my-package-scope/some-name'
export default {
components: {CustomPackageComponent},
}
</script>
I have errors:
[Vue warn]: Error in render: "TypeError: Cannot read properties of undefined (reading 'on')"
found in
---> <DropList>
...
TypeError: Cannot read properties of undefined (reading 'on')
at setCurrentInstance (app.js?id=be8d63a4f2dc42c0bbb5:70359:21)
at normalized (app.js?id=be8d63a4f2dc42c0bbb5:72030:9)
at Proxy.renderSlot (app.js?id=be8d63a4f2dc42c0bbb5:71709:13)
at app.js?id=be8d63a4f2dc42c0bbb5:69361:1276
at Proxy.renderList (app.js?id=be8d63a4f2dc42c0bbb5:71658:22)
at Proxy.__vue_render__$4 (app.js?id=be8d63a4f2dc42c0bbb5:69361:1229)
at VueComponent.Vue._render (app.js?id=be8d63a4f2dc42c0bbb5:72308:28)
at VueComponent.updateComponent (app.js?id=be8d63a4f2dc42c0bbb5:72748:27)
at Watcher.get (app.js?id=be8d63a4f2dc42c0bbb5:73932:33)
at new Watcher (app.js?id=be8d63a4f2dc42c0bbb5:73922:51)
[Vue warn]: Error in beforeMount hook: "TypeError: Cannot read properties of undefined (reading 'off')"
found in
---> <BVTransporter>
...
TypeError: Cannot read properties of undefined (reading 'off')
at setCurrentInstance (app.js?id=be8d63a4f2dc42c0bbb5:70357:51)
at VueComponent.Vue._render (app.js?id=be8d63a4f2dc42c0bbb5:72330:13)
at VueComponent.updateComponent (app.js?id=be8d63a4f2dc42c0bbb5:72748:27)
at Watcher.get (app.js?id=be8d63a4f2dc42c0bbb5:73932:33)
at new Watcher (app.js?id=be8d63a4f2dc42c0bbb5:73922:51)
at mountComponent (app.js?id=be8d63a4f2dc42c0bbb5:72765:5)
at VueComponent.Vue.$mount (app.js?id=be8d63a4f2dc42c0bbb5:79061:12)
at VueComponent.Vue.$mount (app.js?id=be8d63a4f2dc42c0bbb5:81625:18)
at init (app.js?id=be8d63a4f2dc42c0bbb5:136420:13)
at createComponent (app.js?id=be8d63a4f2dc42c0bbb5:139300:9)
[Vue warn]: Error in nextTick: "TypeError: Cannot read properties of undefined (reading 'removeAttribute')"
TypeError: Cannot read properties of undefined (reading 'removeAttribute')
at Array.updateAttrs (app.js?id=be8d63a4f2dc42c0bbb5:140051:13)
at patchVnode (app.js?id=be8d63a4f2dc42c0bbb5:139636:62)
at updateChildren (app.js?id=be8d63a4f2dc42c0bbb5:139515:9)
at patchVnode (app.js?id=be8d63a4f2dc42c0bbb5:139641:29)
at VueComponent.patch [as __patch__] (app.js?id=be8d63a4f2dc42c0bbb5:139804:9)
[Vue warn]: Error in nextTick: "TypeError: Cannot read properties of undefined (reading 'on')"
found in
---> <BVTransporter>
...
If I use this code without package everything is ok. I think, that is's something with vue lifecycle, but I don't have any idea how it fix.
Maybe I need to register my package by another way.
I use npm link for local development.
Also I try to import with Vue.Component(...) in CustomPackageComponent.vue:
<template>
<div>
<drop-list :items="[1, 2]">
<template v-slot:item="{item}">
<drag :key="item">
{{ item }}
</drag>
</template>
</drop-list>
</div>
</template>
<script>
import Vue from "vue";
import {DropList, Drag} from "vue-easy-dnd";
Vue.component('drop-list', DropList);
Vue.component('drag', Drag);
export default {
data() {
return {
someVar: 'foo'
}
},
}
</script>
But I have this error:
[Vue warn]: Unknown custom element: <drop-list> - did you register the component correctly? For recursive components, make sure to provide the "name" option.
found in
---> <CustomPackageComponent> at packages/packages/someScope/someName/src/components/CustomPackageComponent.vue
...

Related

Getting vue-warn in all the vuetify 3 components related to VOverlay (v-dialog, v-tooltip, v-overlay)

I am using Vue 3 with Vuetify 3.0.1. I want to develop a Vue application based on Options API. While trying to make use of a simple v-dialog, I getting following error:
runtime-core.esm-bundler.js?d2dd:40 [Vue warn]: Unhandled error during execution of watcher callback
at <VOverlay ref=Ref< undefined > class="v-dialog" width="500" ... >
at <VDialog modelValue=false onUpdate:modelValue=fn width="500" >
at <VMain>
at <VApp>
at <App>
warn # runtime-core.esm-bundler.js?d2dd:40
runtime-core.esm-bundler.js?d2dd:40 [Vue warn]: Unhandled error during execution of setup function
at <VOverlay ref=Ref< undefined > class="v-dialog" width="500" ... >
at <VDialog modelValue=false onUpdate:modelValue=fn width="500" >
at <VMain>
at <VApp>
at <App>
Uncaught TypeError: globalStack.at is not a function
at eval (webpack-internal:///./node_modules/vuetify/lib/composables/stack.mjs:36)
at callWithErrorHandling (webpack-internal:///./node_modules/#vue/runtime-core/dist/runtime-core.esm-bundler.js:286)
at callWithAsyncErrorHandling (webpack-internal:///./node_modules/#vue/runtime-core/dist/runtime-core.esm-bundler.js:295)
at ReactiveEffect.getter [as fn] (webpack-internal:///./node_modules/#vue/runtime-core/dist/runtime-core.esm-bundler.js:1858)
at ReactiveEffect.run (webpack-internal:///./node_modules/#vue/reactivity/dist/reactivity.esm-bundler.js:225)
at doWatch (webpack-internal:///./node_modules/#vue/runtime-core/dist/runtime-core.esm-bundler.js:1973)
at watchEffect (webpack-internal:///./node_modules/#vue/runtime-core/dist/runtime-core.esm-bundler.js:1778)
at useStack (webpack-internal:///./node_modules/vuetify/lib/composables/stack.mjs:34)
at Object.setup [as _setup] (webpack-internal:///./node_modules/vuetify/lib/components/VOverlay/VOverlay.mjs:151)
at setup (webpack-internal:///./node_modules/vuetify/lib/util/defineComponent.mjs:62)
My setup configuration is not that complex.
App.Vue
<template>
<v-app>
<v-dialog v-model="dialog">
<template v-slot:activator="{ props }">
<v-btn color="primary" v-bind="props"> Open Dialog </v-btn>
</template>
</v-dialog>
</v-app>
</template>
<script lang="ts">
export default {
name: "App",
data() {
return {
dialog: false,
};
},
};
</script>
main.ts
import { createApp } from "vue";
import store from "./store/planner";
import vuetify from "./plugins/vuetify";
import App from "./App.vue";
import router from "./router";
import i18n from "./i18n";
const app = createApp(App);
app.use(vuetify).use(router).use(store).use(i18n);
app.mount("#app");
This occurs on all the vuetify components involving v-overlay.

Failed to resolve component: VuePhoneNumberInput in #ionic-vue

I installed a global component in #ionic-vue, but when using it in another component I get the following error:
[Vue warn]: Failed to resolve component: VuePhoneNumberInput at
<Registro ref=Ref< undefined > key="/registro" isInOutlet=true ... >
at at at
runtime-core.esm-bundler.js:38
[Vue warn]: Failed to resolve
component: VuePhoneNumberInput at <Registro ref=Ref< Proxy {
: {…}, : {…} }
key="/registro" isInOutlet=true ... > at at at
My global register:
import VuePhoneNumberInput from 'vue-phone-number-input';
import 'vue-phone-number-input/dist/vue-phone-number-input.css';
import './theme/variables.css';
const app = createApp(App)
.use(IonicVue)
.use(router);
app.component('vue-phone-number-input', VuePhoneNumberInput);
Other component:
<template>
<ion-page>
<Navigacion :titulo="titulo">
<template v-slot:default>
<div class="titulo-login">Ingresa a Jamuy con tu número de celular</div>
<VuePhoneNumberInput v-model="numero" #update="resultados = $event"></VuePhoneNumberInput>
</template>
</Navigacion>
</ion-page>
</template>

How can I snapshot test a Vue SFC page in Nuxt that only contains a layout using jest

How can I snapshot test a Vue SFC page in Nuxt that only contains a layout using jest.
For example:
<script>
export default {
layout: 'some-layout-name'
};
</script>
I get an error because it is lacking the template part, I could not make it generate a snapshot in snapshot testing in jest.
[Vue warn]: Failed to mount component: template or render function not defined.
found in
---> <Anonymous>
<Root>
at warn (node_modules/vue/dist/vue.runtime.common.dev.js:621:15)
at mountComponent (node_modules/vue/dist/vue.runtime.common.dev.js:4024:9)
at VueComponent.Object.<anonymous>.Vue.$mount (node_modules/vue/dist/vue.runtime.common.dev.js:8392:10)
at init (node_modules/vue/dist/vue.runtime.common.dev.js:3112:13)
at createComponent (node_modules/vue/dist/vue.runtime.common.dev.js:5958:9)
at createElm (node_modules/vue/dist/vue.runtime.common.dev.js:5905:9)
at VueComponent.patch [as __patch__] (node_modules/vue/dist/vue.runtime.common.dev.js:6455:7)
at VueComponent.Vue._update (node_modules/vue/dist/vue.runtime.common.dev.js:3933:19)
You need to ensure you have a <template> element in your Single File Component SFC.
Example.
<template>
<div/>
</template>
<script>
export default {
layout: 'some-layout-name'
};
</script>
N.B. Without the <template> element in your SFC, you'll continue to get the error experienced.
render function or template not defined in the component.

Error while moving component from application to a library

I am having troubles while creating a library of components in top of Vuetify 2.x.
I have created a simple navigation-drawer wrapper:
<template>
<v-navigation-drawer app v-model="drawer">
<v-list-item>
<v-list-item-content>
<v-list-item-title class="title">
Application
</v-list-item-title>
<v-list-item-subtitle>
subtext
</v-list-item-subtitle>
</v-list-item-content>
</v-list-item>
</v-navigation-drawer>
</template>
<script>
export default {
name: 'MySidebar',
data: () => ({
drawer: null,
}),
};
</script>
When this component is placed inside my application, it works as expected. However, when the same component is on a library, the application crashes.
<template>
<v-app>
<my-sidebar/>
</v-app>
</template>
<script>
import MySidebar from 'my-library/src/components/MySidebar.vue'; // Error
import MySidebar from './src/components/MySidebar.vue'; // Works
export default {
name: 'App',
components: {
MySidebar,
},
};
</script>
On the first import, the application fails to get the this.$vuetify object, but when I console.log(this.$vuetify), it is there.
Some of the console messages:
TypeError: Cannot read property 'breakpoint' of undefined
at VueComponent.isMobile (VNavigationDrawer.ts?6ca0:193)
at Watcher.get (vue.runtime.esm.js?f9ee:4473)
...
[Vue warn]: Error in getter for watcher "isMobile": "TypeError: Cannot read property 'breakpoint' of undefined"
found in
---> <VNavigationDrawer>
<MySidebar> at my-library/src/components/MySidebar.vue
<VApp>
<App> at src/App.vue
<Root>
...
TypeError: Cannot read property 'breakpoint' of undefined
at VueComponent.isMobile (VNavigationDrawer.ts?6ca0:193)
at Watcher.get (vue.runtime.esm.js?f9ee:4473)
...
[Vue warn]: Error in created hook: "TypeError: Cannot read property 'application' of undefined"
found in
---> <VNavigationDrawer>
<MySidebar> at my-library/src/components/MySidebar.vue
<VApp>
<App> at src/App.vue
<Root>
Additional Information:
My Library has vuetify as dev dependency for development proposes
I am using the library via npm link
With some help from the Vuetify team, I found out that the problem was that Webpack was using Vuetify from the library instead of using from the app. This was caused by the use of npm link on my-app to use my-library together with Vuetify installed as dev-dependency on my-library.
Some possible solutions:
On my-library, use npm install --only=prod instead of npm install. This will prevent the conflict by not installing Vuetify on the library.
On my-app, add the following lines to vue.config.js:
const path = require('path');
module.exports = {
publicPath: process.env.VUE_APP_PUBLIC_PATH,
configureWebpack: {
resolve: {
alias: {
/* Use vuetify from my-app, not from my-library */
vuetify: path.resolve(__dirname, 'node_modules/vuetify'),
},
},
},
};
This will tell explicitly to Webpack to chose the Vuetify installation from my-app.
Other solutions that did not fit my requirements:
Stop using npm link
Do not install Vuetify on my-library, install it only on my-app
I had the exact same issue and solved it by deleting the node_modules folder in the component library folder (i.e. rm -rf my-library/node_modules in your case).

[Vue warn]: Invalid handler for event "click": got undefined

I am using vue js as my frontend framework and I have defined a #click event on a button. However, when I click it, I am getting following error:-
[Vue warn]: Property or method "getArea" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property.
[Vue warn]: Invalid handler for event "click": got undefined
found in
---> <ElButton> at packages/button/src/button.vue
<ElCard> at packages/card/src/main.vue
<ElCol>
<ElRow>
<ElCol>
<ElRow>
<ElHeader> at packages/header/src/main.vue
<ElContainer> at packages/container/src/main.vue
<ProgressBar> at src/views/Map/components/ProgressBar.vue
I found a similar question at the following link:-
VueJS - Invalid handler for event "click": got undefined
but does not seem to solve the problem
ProgressBar.vue
<template>
<el-col class="progress-bar-icon" :span="6">
<span class="step-text">Step-2<br/></span>
<el-button id="two" class="icon" icon="el-icon-location-outline" circle></el-button>
<el-card v-if="ifLocation" class="dialog-box-card">
<h4 class="heading">Pin Down Your Roof On The Map</h4>
<el-button type="primary" round #click="getArea">Next <i class="el-icon-arrow-right"></i>
</el-button>
</el-card>
</el-col>
</template>
<script>
export default {
name:'progress-bar',
data(){
return {
ifLocation:true,
ifArea:false,
}
},
method:{
getArea(){
this.ifLocation=false
this.ifArea=true
}
}
};
</script>
index.vue
<template>
<div>
<progress-bar></progress-bar>
</div>
</template>
<script>
import ProgressBar from './components/ProgressBar';
export default {
name:'index',
components:{
'progress-bar':ProgressBar,
},
};
</script>
Please change "method" to "methods"
like this :
methods:{
getArea(){
this.ifLocation=false
this.ifArea=true
}
}
I finally found it. An error occurs because we call a function not found in methods. For example; we use the "increase" function in a div, but we don't define this function in methods. When we add this function to methods, the problem disappears.