electron-userland/electron-json-storage

error in production

Holybasil opened this issue · 2 comments

electron: 8.2.0
electron-json-storage: 4.2.0

webPreferences:
      process.env.NODE_ENV === 'development' || process.env.E2E_BUILD === 'true'
        ? {
            nodeIntegration: true
          }
        : {
            // nodeIntegration: true,
            preload: path.join(__dirname, 'dist/renderer.prod.js')
          }

And,
image.png

Hey @Holybasil,

I believe you need to set nodeIntegration: true in order to access the process global object.

What I think its happening is that you can always access process at this point. If the environment is production, then you don't enable nodeIntegration on that renderer process, which eventually makes rimraf crash, as that module presumable does try to access process.

In summary, this doesn't seem related to electron-json-storage, but to the fact that another module (rimraf) is trying to access process, which you are disabling if the environment is production.

I have found a solution.

main.js

import Storage from 'electron-json-storage';
Storage.set("foo", {value: false});
ipcMain.handle(
  'getStoreValue',
  (event, key) =>
    new Promise((resolve, reject) => {
      Storage.get(key, (error, data) => {
        if (error) {
          reject(error);
        } else {
          resolve(data);
        }
      });
    })
);

renderer.js

import { ipcRenderer } from 'electron';
ipcRenderer
    .invoke('getStoreValue', 'foo')
    .then(data => console.log(data, 'data')); // {value: false} "data"

And 'set' is just like this way.