Jun Yan
Jun Yan

Reputation: 21

vue-session: Uncaught TypeError: Cannot set properties of undefined (setting '$session')

I just install vue-session plugin to my project(vue 3 with Vite), with the setup like below:

import { createApp } from 'vue'
import App from './App.vue'
import VueSession from 'vue-session'  <---
import router from './router.js' // 

createApp(App).use(router).use(VueSession).mount('#app')

But when I tried to reload the page, it shows:

Uncaught TypeError: Cannot set properties of undefined (setting '$session')
at Object.VueSession.install (index.js:13:19)
at Object.use (runtime-core.esm-bundler.js:3808:28)
at main.js?t=1648710456054:7:28

The other plugin also show same error:

Uncaught TypeError: Cannot set properties of undefined (setting '$cookies')
at Object.install (vue-cookies.js:22:21)
at Object.use (runtime-core.esm-bundler.js:3808:28)
at main.js?t=1648712611253:7:28

Source: vue-session

Vue.prototype.$session = {   <--this line
    flash: {
        parent: function(){
            return Vue.prototype.$session;
        },
        get: function(key){
    ....

vue-cookies

var VueCookies = {
// install of Vue
install: function (Vue) {
  Vue.prototype.$cookies = this;
  Vue.$cookies = this;
},

Can somebody help a JS newbie?

Upvotes: 1

Views: 1836

Answers (1)

Clem
Clem

Reputation: 2312

It s a Vue2 plugin. It wont works with Vue3.

Upvotes: 1

Related Questions