sindresorhus / electron-store

Simple data persistence for your Electron app or module - Save and load user preferences, app state, cache, etc
MIT License
4.57k stars 148 forks source link

Error when calling store.set(). TypeError: Cannot read properties of undefined (reading 'env') #249

Closed evlquaker closed 1 year ago

evlquaker commented 1 year ago

Whenever I try to call store.set() I get the error message below.

TypeError: Cannot read properties of undefined (reading 'env') at ElectronStore._write (C:\Users\me\OneDrive\myProg\node_modules\conf\dist\source\index.js:370:21) at ElectronStore.set store [as store] (C:\Users\me\OneDrive\myProg\node_modules\conf\dist\source\index.js:296:14) at ElectronStore.set (C:\Users\me\OneDrive\myProg\node_modules\conf\dist\source\index.js:189:20) at IpcMainImpl. (C:\Users\me\OneDrive\myProg\main\main.js:101:15)

The problem seems to be related to 'process' being undefined in node_modules\conf\dist\source\index.js. I am using Electron v14.2.9

store.get() works as expected. Does anyone know why this might be happening?

sindresorhus commented 1 year ago

This is a problem with your bundler config, not this package.

evlquaker commented 1 year ago

Hi @sindresorhus , thanks for writing back. The issue is happening before bundling in the testing environment. The problem seems to be fixed by changing line 370 in index.js in the conf module from 'if (process.env.SNAP)' to 'if (process && process.env.SNAP)'.

This might just be covering up a bigger issue on my end if process is supposed to be defined at that point. Sorry I am fairly new to Electron development.

Best Regards, ~Mike