Registry / storage / electron-store

electron-store

JSON →
library11.0.2jsnpmunverified

Simple data persistence for Electron apps and modules, saving and loading user settings, app state, and cache as a JSON file in the user data directory. v11.0.2 is the current stable release, requiring Electron 30+ and Node.js 20+. The package is native ESM only (no CommonJS). Key differentiators: JSON Schema validation via ajv, atomic disk writes, dot-notation access for nested properties, migration support for version upgrades. Actively maintained by Sindre Sorhus.

npm install electron-store
INSTALL
IMPORT
SIG · ELECTRON-STORE
E
electron-store
storagejavascriptv11.0.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Store
✓ import Store from 'electron-store'
✗ const Store = require('electron-store')
Default export. Package is ESM-only since v9; CommonJS require will fail.
Store
✓ import Store from 'electron-store'
✗ import { Store } from 'electron-store'
Named import does not work; uses default export.
electron-store (type)
✓ import type Store from 'electron-store'
✗ import Store from 'electron-store' (not needed for types)
For TypeScript, you can use type-only import to avoid runtime value.

Creates a store with defaults and schema validation, then demonstrates set, get, delete, and clear operations.

import Store from 'electron-store'; const store = new Store({ defaults: { unicorn: '🦄', foo: { bar: true } }, schema: { unicorn: { type: 'string' }, 'foo.bar': { type: 'boolean' } } }); store.set('unicorn', '🦄'); console.log(store.get('unicorn')); //=> '🦄' store.set('foo.bar', true); console.log(store.get('foo')); //=> { bar: true } store.delete('unicorn'); console.log(store.get('unicorn')); //=> undefined store.clear(); console.log(store.size); //=> 0
Debug
Known issues
breakingelectron-store v9+ is ESM-only and no longer provides a CommonJS export. Using require() throws an error.
fix
Convert your project to ESM (use 'import' instead of 'require'). More info: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
affects: >=9.0.0
breakingelectron-store v11 drops support for Node.js <20 and Electron <30.
fix
Update Node.js to >=20 and Electron to >=30.
affects: >=11.0.0
gotchaThe `migrations` feature is known to have bugs and is not actively maintained. Use with caution.
fix
Consider implementing custom migration logic outside the library.
affects: *
gotchaData is saved as config.json in app.getPath('userData'). Ensure the app is ready before accessing the store.
fix
Access store after app 'ready' event or in the main process only if using in renderer.
affects: *
deprecatedThe `beforeEachMigration` option has been deprecated. Use migration functions directly.
fix
Remove `beforeEachMigration` and include logic inside migration handlers.
affects: >=10.0.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module
Project uses CommonJS (require) but electron-store is ESM-only since v9.
fix
Switch to ESM by setting 'type': 'module' in package.json and using import syntax.
Error: Config schema violation: 'foo' should be number
Trying to set a value that doesn't match the JSON schema defined in options.
fix
Ensure the value passed to store.set() conforms to the schema type and constraints.
TypeError: store.set is not a function
Using a named import { Store } instead of default import.
fix
Use 'import Store from 'electron-store'' (default import).
Error: The 'electron-store' package is not compatible with CommonJS
CommonJS require in a Node.js environment that doesn't support ESM interop.
fix
Set 'type': 'module' in package.json or rename file to .mjs.
Upgrade
Version history
11.0.2latest on npm
Audit
Dependencies
ajvoptionalUsed for JSON Schema validation when schema option is provided.
confrequiredUnderlying configuration store library used for core functionality.
atomicallyrequiredEnsures atomic writes to disk to prevent corruption.
Agent activity
32 hits · last 30 days
node
30
OpenAI (training)
1
Resources
electron-store — npm install electron-store · libregistry