Circular dependency of stores not working #2229
Replies: 2 comments 4 replies
-
@Thomas-1985 Did you solve this? I have the same scenario but not the same error. Mine is : |
Beta Was this translation helpful? Give feedback.
-
Note EDIT: 🤦 i've realized that the issue is not with pinia, but just regular javascript circular references, you can't obvious mutually import modules this way. Solving circular deps issues in big apps is a non-trivial problem and there's plenty of articles around. I've found a workaround by using a pinia plugin that exposes a Have the same issue! Here's the fork of the the pinia todo app in the pinia-playground
Anyone figured it out? Cheers ✌️ |
Beta Was this translation helpful? Give feedback.
-
We want to migrate from Vuex 3.5 to Pinia and have a problem with stores, which call each other.
We have a
rootStore
and annewStore
in Pinia.In an action of the
rootStore
, we try to useconst newStore = useNewStore();
Otherwise in an action of the the new store, we try to use
const rootStore = useRootStore();
This will not work, in the root store we get the error
TS2448: Block-scoped variable 'useNewStore' used before its declaration.
I guess this is because in the
defineStore
calls, each other function is called, creating a circular dependency.The pinia introduction says: "You can even have circular dependencies of stores"
Also we have read that this is possible here: https://pinia.vuejs.org/cookbook/composing-stores.html
But the example is using a
setup()
function for the stores, we use the same option structure as vuex (with data, getters, actions and so on) with the options api (with Vue 2.7)How can we solve this? Thanks for your help.
Beta Was this translation helpful? Give feedback.
All reactions