vue-electron / vuex-electron

Integration of Vuex and Electron
MIT License
305 stars 97 forks source link

Uncaught Error: [Vuex Electron] Storage is not valid. Please, read the docs. #38

Open mxj7000 opened 5 years ago

mxj7000 commented 5 years ago

Hi, Integrate the vuex into the electron , my application will run to this issues,

Uncaught Error: [Vuex Electron] Storage is not valid. Please, read the docs. at a (C:\Users\Administrator\Desktop\win-unpacked\resources\app.asar\node_modules\vuex-electron\dist\persisted-state.js:1) at C:\Users\Administrator\Desktop\win-unpacked\resources\app.asar\node_modules\vuex-electron\dist\persisted-state.js:1 at C:\Users\Administrator\Desktop\win-unpacked\resources\app.asar\node_modules\vuex\dist\vuex.common.js:345 at Array.forEach () at new Store (C:\Users\Administrator\Desktop\win-unpacked\resources\app.asar\node_modules\vuex\dist\vuex.common.js:345) at Object. (renderer.js:1) at d (renderer.js:1) at n (renderer.js:1) at Object. (renderer.js:1) at d (renderer.js:1)

Who knows going on with this? I confusion with this problem about on week;

mxj7000 commented 5 years ago

Resolved issues, we don't use the vuex-electron to do it;

akodkod commented 5 years ago

https://github.com/vue-electron/vuex-electron/issues/44

zjruan commented 5 years ago

vuex-electron‘s createPersistedState method , depend electron-store <- conf <- write-file-atomic. and the method writeFileSync in write-file-atomic use fs.renameSync.

But, fs.renameSync Sometimes it goes wrong when multithreading because race condition。and every electron window is a rendering process。So,there is no solution until write-file-atomic solves the problem.

We can find that the root cause of the problem is multithreading, so here's an idea. We can also rewrite createPersistedState method to store data locally, only in the main process

ZhangZheng-GIS commented 4 years ago

Resolved issues, we don't use the vuex-electron to do it;

Hi, what did you change?

ZhangZheng-GIS commented 4 years ago

vuex-electron‘s createPersistedState method , depend electron-store <- conf <- write-file-atomic. and the method writeFileSync in write-file-atomic use fs.renameSync.

But, fs.renameSync Sometimes it goes wrong when multithreading because race condition。and every electron window is a rendering process。So,there is no solution until write-file-atomic solves the problem.

We can find that the root cause of the problem is multithreading, so here's an idea. We can also rewrite createPersistedState method to store data locally, only in the main process

Hi @zjruan, I used a background process and got this error. Is there a specific solution?

espace-4-0 commented 4 years ago

Hi Guys,

Is the bug fixed ?

Best regards, Lenaïc

Gkiokan commented 2 years ago

I got a fix for you guys. I struggled with that for my application on my windows users and it is really annoying.
However, I've found a valide workarround.

The error and crash happens due the thrown error in the plugin.
So you 2 options. Either you fix the race condition or you handle the Storage creation properly.

I am using 4 windows on my side and all of them have parallel access to the storage which makes everything complicated but however I could get it running without hassle once I put the creation in a while loop.

function createStore(){
    return new Vuex.Store({
      plugins: [
        pathify.plugin,
        createPersistedState({
          throttle: 1000,
          whitelist: (mutation) => true,
        }),
        createSharedMutations()
      ],
      modules
    })
}

let store

while(store === undefined){
  try {
      store = createStore()
      break;
  }
  catch(e){
      // alert("Error in Store, guess race condition. Recreating Storage." + e)
      continue;
  }
}

export default store