vuex-electron icon indicating copy to clipboard operation
vuex-electron copied to clipboard

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

Open mxj7000 opened this issue 5 years ago • 7 comments

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 avatar Apr 29 '19 07:04 mxj7000

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

mxj7000 avatar May 11 '19 08:05 mxj7000

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

akodkod avatar Aug 29 '19 14:08 akodkod

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

zjruan avatar Nov 07 '19 07:11 zjruan

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

Hi, what did you change?

ZhangZheng-GIS avatar Jun 02 '20 06:06 ZhangZheng-GIS

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?

ZhangZheng-GIS avatar Jun 03 '20 07:06 ZhangZheng-GIS

Hi Guys,

Is the bug fixed ?

Best regards, Lenaïc

espace-4-0 avatar Oct 08 '20 12:10 espace-4-0

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

Gkiokan avatar Jan 08 '22 16:01 Gkiokan