danielroe/typed-vuex

fix: Cannot set property application of #<Object> which has only a getter

quezadaesteban opened this issue ยท 3 comments

๐Ÿ› The bug

The app breaks at lunch.

๐Ÿ› ๏ธ To reproduce
Creating a project with yarn create nuxt-app someapp and installing nuxt-typed-vuex. After adding it to the build modules, when launching the app it shows the black loading spinner and in the console it says:

TypeError: Cannot set property application of #<Object> which has only a getter
    at eval (index.es.js?9e80:53)
    at Array.forEach (<anonymous>)
    at createAccessor (index.es.js?9e80:52)
    at useAccessor (index.es.js?9e80:58)
    at eval (index.es.js?9e80:61)
    at Array.forEach (<anonymous>)
    at useAccessor (index.es.js?9e80:59)
    at eval (index.es.js?9e80:66)
    at _callee$ (nuxt-typed-vuex.js?679e:8)
    at tryCatch (runtime.js?96cf:63)

I've tried many things, I'm using the helper functions in every module, I even sent and empty getAccessorType({}) and it stills shows the error in the console. It only disappears when removing the nuxt-typed-vuex from the buildModules.

๐ŸŒˆ Expected behaviour
It should not show any error.

โ„น๏ธ Additional context
It is the only buildModule I'm using aside from '@nuxt/typescript-build' and '@nuxtjs/vuetify' that come with the installation.

@quezadaesteban I can't replicate this so I think it's specific to how you've set up your store. Would you share a code repro - for example using https://template.nuxtjs.org/ ?

@quezadaesteban I can't replicate this so I think it's specific to how you've set up your store. Would you share a code repro - for example using https://template.nuxtjs.org/ ?

After a lot of digging I found the issue. That message can happen when you have commits or actions with the same name as a state or getter in the file. In the specific case I had an application state variable and an application action that fetches application data from a server. In other instance I had a currentProject commit with the same name as a currentProject getter. I solved them by changing the names.

Reading the error, because it seems it first assigns the state and getters into the accessor as read only, when trying to assign an action or mutation with the same name it throws that error, hence de # meaning a readonly or private property.

Thank you very much for your quick response and I hope this helps anyone else with a similar issue.

@quezadaesteban Glad it's sorted!