level: IO Error in packaged Electron app

I’m making an Electron app with LevelDB and want to use asar in packaging, but at startup it gives this error:

Uncaught Exception:
OpenError: IO error: ./hypershare.db/LOCK: No such file or directory
    at /Users/gerhard/dev/node/hypershare-app/dist/Hypershare-darwin-x64/Hypershare.app/Contents/Resources/app.asar/node_modules/levelup/lib/levelup.js:119:34
    at /Users/gerhard/dev/node/hypershare-app/dist/Hypershare-darwin-x64/Hypershare.app/Contents/Resources/app.asar/node_modules/leveldown/node_modules/abstract-leveldown/abstract-leveldown.js:39:16

I tried to unpack the file that creates the db, so it isn’t in the .asar file, but it gives the same error.

If I don’t use asar it works though.

How could I avoid this error?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 15 (5 by maintainers)

Most upvoted comments

Thank you, @ralphtheninja . Yeah, I found it. Actually @BrunoBernardino 's answer have solved my problem. Thanks, bro. But I did not notice that I run electron:serve and open the packaged app at the same time.

@Alecyrus here’s the relevant code (sorry, that repo/app got sold and is no longer publicly available):

// renderer.js
const { remote } = require('electron');
const { app } = remote;
const appName = 'Oikon 2';
const appData = `${app.getPath('appData')}/${appName}`;

// This is in another file, but I've simplified for this showcase purpose here
const database = new PouchDB(`${appData}/database`);

Basically the main problem here was PouchDB couldn’t access that app location, but electron can access the appData path, which will depend on the OS.

I hope that helps!

Indeed I fixed it by “forcing” the directory (somewhere it wasn’t being set properly, after packaging): https://github.com/BrunoBernardino/Oikon2-Mac/pull/2/files#diff-0aa32d546cef508ec48190878d4d7f50R17

Happy you managed to solve it! Closing this issue, if you don’t mind 😃