Vuejs Cannot read property 'use' of undefined error

I'm trying to integrate a Datatable plugin () 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> <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 ?

4

3 Answers

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({ ... }) 

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:

I faced the same error in my vue-app.

import Vue from 'vue'; import VueRouter from 'vue-router'; ...some more imports here.... Vue.use(VueRouter); ... 

The error was cannot read property 'use' of undefined. Which means, it had a problem with reading Vue. I checked my package.json and package-lock.json (for whether I installed in my local). Everything seemed ok. I had both Vue and Vue-router.

Deleting node_modules and re-installing worked for me.

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like