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

Cannot find module 'conf' #241

Closed ifzm closed 1 year ago

ifzm commented 1 year ago

I use electron-builder to build the package successfully, but this error appears when I run it, what could be the reason? thanks )

ifzm commented 1 year ago

image

irg1008 commented 1 year ago

Why did you closed it and not provide the solution?

SSmJaE commented 1 year ago

Reason

The readme claims

Initializer to set up the required ipc communication channels for the module when a Store instance is not created in the main process and you are creating a Store instance in the Electron renderer process only.

But I believed it might be working only under the premise that nodeIntergration is false

Since electron-store is merely a wrapper for conf to make it appropriate for electron, initRenderer may employ some tricks to make it work properly (possibly only when nodeIntergration is false)

So when nodeIntergration is true, initRenderer results in the error Cannot find module "conf"

Solution

Because we have turn nodeIntergration on, there is no longer a requirement for electron-store, we can utilize conf directly in renderer process, and main process doesn't require any specific imports

Yeuoly commented 1 year ago

you should use

import electronStore from 'electron-store'

instead of using

const electronStore = require('electron-store')
ifzm commented 1 year ago

Why did you closed it and not provide the solution?

I have this problem because I use it in the renderer, it should be related to the post-build, I later changed to ipc no problem @irg1008