Vuejs Cannot read property 'use' of undefined error
Solution 1
Adding the following in weback.config.js seemed to do the trick:
module.exports = {
resolve: {
alias: {
...
'vuejs-datatable': 'vuejs-datatable/dist/vuejs-datatable.esm.js',
...
}
},
}
Based on discussion here:
https://github.com/pstephan1187/vue-datatable/issues/50
Solution 2
You need to add plugin before your main Vue
instance is initialized; See using vue plugins here, which says:
Use plugins by calling the Vue.use() global method. This has to be done before you start your app by calling
new Vue()
.
For your case, move
import Vue from 'vue'
Vue.use(DatatableFactory)
to your main.js
, so it looks like:
import Vue from 'vue'
Vue.use(DatatableFactory)
// some other code
new Vue({
...
})
![Fabul](https://i.stack.imgur.com/0GQrw.jpg?s=256&g=1)
Fabul
Updated on August 21, 2022Comments
-
Fabul almost 2 years
I'm trying to integrate a Datatable plugin (https://www.npmjs.com/package/vuejs-datatable) in my Vue application and I'm getting an error in my console.
Uncaught TypeError: Cannot read property 'use' of undefined at eval (vuejs-datatable.js?b015:1) at Object.eval (vuejs-datatable.js?b015:1) at eval (vuejs-datatable.js:4) at Object../node_modules/vuejs-datatable/dist/vuejs-datatable.js (app.js:10170) at __webpack_require__ (app.js:679) at fn (app.js:89) at eval (selector.js?type=script&index=0!./src/views/tables/data-table.vue:2) at Object../node_modules/babel-loader/lib/index.js!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./src/views/tables/data-table.vue (app.js:1438) at __webpack_require__ (app.js:679) at fn (app.js:89)
My dataTable.vue file:
<template lang="html"> <section class="data-table"> <datatable :columns="columns" :data="rows"></datatable> </section> </template> <script lang="js"> import Vue from 'vue' import DatatableFactory from 'vuejs-datatable' export default { name: 'DatatablePage' } Vue.use(DatatableFactory) </script>
And whenever i try to use 'Vue.use(PluginName)' when integrating a plugin, i get the similar error. I'm new to VueJS. Is there anything i need to do ?