electron-store icon indicating copy to clipboard operation
electron-store copied to clipboard

Error: EEXIST file already exists mkdir with electron 15

Open nvdai2401 opened this issue 3 years ago • 1 comments

Hi, thanks for an awesome library!

After upgrading electron from version 12 to version 15, my windows app threw an error (see the screenshot below) when calling store.set(key, 'value'). Before upgrading, the app works well with electron 12, 13, and 14. By following the error message, I checked the conf codebase and found that the library calls _ensureDirectory before setting a value to store (see more at https://github.com/sindresorhus/conf/blob/main/source/index.ts#L355-L362) and the error was thrown by _ensureDirectory.

Does anyone know what's happening?

  • The error Screen Shot 2021-09-30 at 17 42 19

  • My dependencies

{
  ...
  "devDependencies": {
    "@types/jest": "^27.0.1",
    "@types/ws": "^7.4.4",
    "cross-env": "^7.0.3",
    "electron": "14.0.1",
    "electron-builder": "^22.10.5",
    "electron-log": "^4.3.5",
    "electron-notarize": "^1.0.0",
    "electron-rebuild": "^3.2.3",
    "filesize": "^8.0.3",
    "jest": "^27.0.6",
    "jest-extended": "^0.11.5",
    "playwright": "^1.14.1",
    "prettier": "^2.3.0",
    "terser": "^5.9.0",
    "ts-jest": "^27.0.5",
    "typescript": "^4.0.2"
  },
  "dependencies": {
    "axios": "^0.21.1",
    "dotenv": "^10.0.0",
    "electron-deeplink": "^1.0.6",
    "electron-squirrel-startup": "^1.0.0",
    "electron-store": "^8.0.1",
    "electron-updater": "^4.3.9",
    "electron-windows-notifications": "^3.0.8",
    "ws": "^7.4.6"
  }
}
  • Node version: 14.15.1

  • OS version: Windows 10, version 19043.928, x64

  • I use Advanced Installer Express to build MSIX package for my windows app

nvdai2401 avatar Sep 30 '21 14:09 nvdai2401

TL;DR: for me it helped to delete %APPDATA%\yourappname before installing the MSIX package. (you may have to uninstall, then delete, then reinstall)

Starting to pack up an electron app for the first time I encountered the same issue on

  • node 14.18.0
  • electron 15.0.0
  • Windows 10 Pro, 10.0.19042, x64

However the issue only comes up when using the MSIX package, neither in the source .exe using electron-forge, nor when running directly via npm start (even though all three variants use the same config storage).

Potentially this is related to some sandboxing / containerization that MSIX packaged apps have to work with, it seems that Windows is doing some redirection behind the scenes (https://docs.microsoft.com/en-us/windows/msix/desktop/desktop-to-uwp-behind-the-scenes).

Digging a bit deeper I found that Windows creates a shadow copy of the app data in %LOCALAPPDATA%\Packages\yourpackageidentifierhere\LocalCache\Roaming, interestingly while the standalone app creates a folder called yourappname in %APPDATA%, the MSIX version creates a file called yourappname (which then seems to trigger the EEXIST error when mkdir is called).

Now interestingly while working with this I found out that (though I'd be happy to have confirmation on that) this only seems to be a problem, if you already have an %APPDATA%\yourappname folder (for example from testing on the same machine) which Windows would "port over". When I delete the "normal" folder in %APPDATA%, the whole thing works flawlessly. Almost seems like something goes wrong when Windows try to shadow copy the existing data.

I'm not sure if this is Windows' fault, something with the way, files are accessed and if not, who of electron-store, electron or node can even fix this. However given that at least for me the end goal is an MSIX file for distribution, this workaround is "good enough" (as normal users will never have installed a non-MSIX version). Maybe this helps someone else

TriPhoenix avatar Oct 05 '21 12:10 TriPhoenix