Electron-builder: sqlite3 db-file is not found within app.asar

Created on 17 Apr 2017  路  8Comments  路  Source: electron-userland/electron-builder

happy easter,

Trying to create a build for mac osx, also working on a mac.
This is a part of my package.json to show what i use (based on electron-boilerplate-sqlite):

"dependencies": {
    "sqlite3": "^3.1.8"
  },
  "devDependencies": {
    "electron": "^1.6.2",
    "electron-builder": "^10.17.3"
  }

This is how i set the path to the db-file
const dbFile = path.join(__dirname, '/appData.db');

In the build the path is like this:
/Users/[USERNAME]/[PATH-TO-CONTENT]/Contents/Resources/app.asar/app/appData.db

... and I end up with an error:
SQLITE_CANTOPEN: unable to open database file

Now setting asar to false in the build-options. The path is now like this:
/Users/[USERNAME]/[PATH-TO-CONTENT]/Contents/Resources/app/app/appData.db

The app works fine.
How can i solve this problem?

regards, jo

question readme improvement

Most helpful comment

thanks for the hint, but it seems to be not very handy... i end up here:

"extraResources": ["appData.db"],

and here:

const dbFile = path.join(__dirname, '/appData.db').replace('/app.asar', '');

hmmm...

All 8 comments

thanks for the hint, but it seems to be not very handy... i end up here:

"extraResources": ["appData.db"],

and here:

const dbFile = path.join(__dirname, '/appData.db').replace('/app.asar', '');

hmmm...

Update: add examples to doc.

@wende60

"extraResources": ["appData.db"],

Did it work?

as mentioned above, it works only if i toggle the path like here:
const dbFile = path.join(__dirname, '/appData.db').replace('/app.asar', '');

I stopped testing here as I switched to a completely different setup using pouchdb...

cheers, jo

Fix on electron side is required. https://www.npmjs.com/package/hazardous

cool, thanks :)

"extraResources": ["appData.db"],
and
const dbFile = path.join(__dirname, '/appData.db').replace('/app.asar', '');

Worked for me!!!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

leo picture leo  路  3Comments

jhg picture jhg  路  3Comments

JohnWeisz picture JohnWeisz  路  3Comments

lbssousa picture lbssousa  路  3Comments

omarkilani picture omarkilani  路  3Comments