Skip to content
This repository has been archived by the owner on Sep 6, 2020. It is now read-only.

TypeError: Vue.set is not a function #22

Open
sne11ius opened this issue Nov 5, 2017 · 3 comments
Open

TypeError: Vue.set is not a function #22

sne11ius opened this issue Nov 5, 2017 · 3 comments

Comments

@sne11ius
Copy link

sne11ius commented Nov 5, 2017

I created a new project with vue-cli, added vue-model dependency and want to try it out.

I have this:

import Vue from 'vue'
import VueModel from 'vue-model'

Vue.use(VueModel, {
  WatchEntry: {
    attributes: [
      'id',
      'url'
    ],
    http: {
      baseRoute: '/my/watches'
    }
  }
})

Now I want to load all models from the server:

methods: {
    loadData () {
      console.debug(this.$model('WatchEntry').index())
    }
  }

And I get:

TypeError: Vue.set is not a function
    at Errors.set (Errors.js?4eb3:23)
    at new Errors (Errors.js?4eb3:7)
    at Model.setData (Model.js?6d83:32)
    at new Model (Model.js?6d83:12)
    at VueModel.$model (VueModel.js?f341:38)
    at apply (lodash.js?3387:496)
    at wrapper (lodash.js?3387:5356)
    at VueComponent.eval [as $model] (VueModel.js?f341:171)
    at VueComponent.loadData (HelloWorld.vue?b703:39)
    at Proxy.boundFn (vue.esm.js?efeb:187)

Any ideas?

@sne11ius
Copy link
Author

sne11ius commented Nov 5, 2017

Also, I am currently using LarryBattle s fork, and this is a webpack project...

@cmrd-senya
Copy link

cmrd-senya commented Nov 21, 2017

I have the same problem.

I guess it happens because you're using Vue.js bundled as ES2016 module -- I see vue.esm.js file in your backtrace.

The problem is that vue-model is trying to require vue.js using node.js require directive. However when vue is provided as ES2016 module, requiring it doesn't work this way anymore.

The only solution I came up with is to replace requires with ES2016 imports. This works for me, but it obviously breaks the compatibility with environments where ES2016 is not available. Unfortunately I don't know a better solution, otherwise I would provide a PR.

Here are my changes which made it work for me: cmrd-senya@5034e2a

If anyone suggests a proper solution I'll be able to test it and submit a PR.

@ghost
Copy link

ghost commented Apr 7, 2019

Ran into this same problem today. I've been messing around with Vuex server-side and was using Vue.set in my mutations, and then started running the same mutations client-side and was like WHAT IS WRONG THESE ARE THE SAME.

I'm guessing it's just because I'm using Nuxt but I enabled Typescript? @cmrd-senya 's solution worked for me (using import/from syntax instead of require syntax)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants