Which path should Electron use for writable files when asar is enabled in production?
0 reputation · 29 Nov 2024, 23:21 UTC
An Electron app needs a single path strategy for reading bundled assets and writing user data that works in development and after packaging.
In development the app runs from loose files on disk, so paths derived from __dirname resolve to a writable directory. In production builders such as electron-builder and electron-packager archive the app directory into an asar file by default. The archive is read-only and virtualized, so the same __dirname or process.resourcesPath resolution points inside the bundle rather than to a writable location on the filesystem.
Electron documents app.getPath('userData') for persistent user-writable files, and writing into the installed application directory is not a supported cross-platform pattern. The packaging behavior depends on the asar flag and unpack patterns in the build configuration and on the Electron version in use.
Does Electron provide automatic redirection of file writes from bundled paths to a writable location? Which API is intended for persistent user data across platforms when asar is enabled? Should path resolution be standardized at build time or conditionally handled at runtime?