question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

sqlite3 db-file is not found within app.asar

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
wende60commented, Apr 17, 2017

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…

1reaction
salmidivcommented, Sep 28, 2022

hi evryone i fix it with this in packege.json , in build section add: “extraResources”: [ “path/to/database.sqlite3” ], in main.js add use: const getDBPath = (filename) => { let base = app.getAppPath() if (app.isPackaged) { base = base.replace(‘\app.asar’, ‘’) } return path.resolve(base, path/to/${filename}.sqlite3) }

Read more comments on GitHub >

github_iconTop Results From Across the Web

sqlite3 db file not created immediately after app installation ...
I`m creating an windows app using React and Electron JS with database file using sqlite3. Im saving the database file in the '/databases' ......
Read more >
DB file sqlite not found
What happened here is that the package built a database and stored it in the file cache, but then that database was wiped...
Read more >
How do I access a Sqlite3 database from an Electron ... - Reddit
I am currently writing an application using Electron and BetterSqlite. I build the AppImage like this: npm run build && electron-builder build.
Read more >
errno: 14, code: 'sqlite_cantopen' - You.com | The AI Search ...
I have this Electron app that uses a SQLite Database. So first it checks if database exist on the appData folder (I'm on...
Read more >
[Fixed]-Anonymise SQLite database? - appsloveworld.com
Featured post · In your application, hold the fake names in two arrays - one for male and one for female. · Do...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found