[Vuejs]-Importing the same module twice throws ReferenceError

0πŸ‘

βœ…

It turned out to be a circular dependency in the end. Even if i didn’t belive in it for most of the time.

DocumentImageStore β†’ DocumentImageService β†’ ServiceBase β†’ NotificationStore.

As DocumentImageStore and NotificationStore resolve from the same vuex-store, in some case the dependency seems not to get resolved, while in other it does (I guess depending on which gets asked for first).

I resolved it by creating a lazy import for the NotificationStore in the Service:

const getStore = () => import("./../store");

export const createNotification = function(message) {
  getStore().then(store => {
    store.default.dispatch("notificationStore/createNotification", message)
  });
}

I guess best would be to resolve the circular dependency completely, but at the current point I don’t see how to do this the way it’s implemented right now.

Leave a comment