Usage of electron-store in Renderer Processes

See original GitHub issue

Greetings, I need some help 🙏 I’ve been trying to implement some data persistance using electron-store. But somehow, when I import it in the renderer process, the compilation keeps failing and throwing errors. I’m using VueJS.

The error messages

Module not found: Error: Can't resolve 'path'  ...
Module not found: Error: Can't resolve 'fs' ...
Module not found: Error: Can't resolve 'crypto' ...

config.js which is located in src folder.

const Store = require('electron-store');

const schema = {
    general: {
        type: 'object',
        properties: {
            gpu: { type: 'boolean' },
            openOnStartup: { type: 'boolean' },
            tray: { type: 'boolean' },
        },
        default: {
            gpu: true,
            openOnStartup: false,
            tray: true,
        }
    },
    theme: {
        type: 'object',
        properties: {
            modes: {
                type: 'string',
                enum: ['dark', 'light', 'system'],
                default: 'dark',
            },
            themes: {
                type: 'object',
                properties: {
                    name: { type: 'string'},
                    colours: {
                        type: 'array',
                        items: {
                            type: 'string'
                        },
                        // TODO: Add default theme
                        default: [],
                    }
                }
            }
        }
    }
};

const config = new Store({schema});

export default config;
<script>
      import config from "/src/config";
      console.log(config.get('general'))
</script>

Importing it only into the main process works fine. But the adding it to a renderer process from a vue component throws those errors mentioned above.

package.json dependencies

"dependencies": {
      "electron": "^15.3.1",
      "electron-store": "^8.0.1",
}

Tried to follow the same configuration as Caprine’s config but I still get the same errors.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:11

github_iconTop GitHub Comments

3reactions
itsgoofercommented, Mar 5, 2022

You literally documented you can use it in the renderer process here: https://github.com/sindresorhus/electron-store#initrenderer

2reactions
1923998238commented, Jan 19, 2022

你需要使用 ipcrenderer 。处理 ipcRenderer

我还没有尝试使用 ipcrenderer,但我仍然更喜欢导入和使用商店。它应该按照此处所述的任何一种方式工作🔽 https://github.com/sindresorhus/electron-store#how-do-i-get-store-values-in-the-renderer-process-when-my-store-was-initialized-in-the-main-过程

Persistent storage needs to access your hard disk. You can’t access your hard disk directly in the rendering process, so the build will report an error

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to store local data with electron-store and get these data ...
So your only option to send and received data between the main and renderer processes is by using ipc messaging.
Read more >
Electron Store
Electron strongly recommends disabling node integration in the renderer process, which is now the default. IPC is required to securely pass values between...
Read more >
Deep dive into Electron's main and renderer processes
Electron uses interprocess communication (IPC) to communicate between processes — same as Chromium. IPC is sort of like using postMessage ...
Read more >
Using Typescript with electron-store - Ryosuke
Why use electron-store? · Local Storage and cookies require you to JSON. · electron-store is built with ajv, a data validation library (similar...
Read more >
Top 5 electron-store Code Examples - Snyk
How to use electron-store - 10 common examples · To help you get started, we've selected a few electron-store examples, based on popular...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found