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 native dependency crashes on MAS build

See original GitHub issue
  • Version: 22.3.2
  • Target: mas

This is my first Electron app so probably I am just missing a step or two to resolve this issue. Or maybe it’s a bug.

My electron app uses a SQLite database and requires the sqlite3 npm package. To work in the development environment it must be rebuilt into a binary file using electron-rebuild. This works fine in development. But when I build for the MAS using the required sandbox entitlement it crashes on launch. To isolate the issue I used the process on a Hello World app. I can build it for the MAS fine but if I install the sqlite3 dependency and require it (even without using the database) it crashes on launch. Below are the messages. I highlighted in yellow what seems to be significant. error-img1

error-img2b

Appears to be an issue with signing the sqlite3 native dependency if I follow it correctly. Says something about Library Validation and library load disallowed by system policy. Do I need to take some additional steps?

### Additional Information: • I have the relevant signing certificates installed: 3rd Party Mac Developer Application and 3rd Party Mac Developer Installer. • I’m not requesting any entitlements other than the required ones for sandboxing.

    <key>com.apple.security.app-sandbox</key><true/>
    <key>com.apple.security.application-groups</key>
    <array>
      <string>12345ABCDE.com.domainname.appname</string>
    </array> 

• I created a provision profile for the app using my 3rd Party Mac Developer Application certificate. It’s in a file at the project’s root directory called MacAppStore.provisionfile.

MAS build console logs During the MAS build for production, sqlite3 is rebuilt as a native dependency. Below are the console logs:

•   electron-builder  version=22.3.2   os=18.7.0
•   loaded configuration  file=package.json   ("build" field)
•   writing effective config    file=dist/builder-effective-config.yaml
•   rebuilding native dependencies    dependencies=sqlite3@4.1.1 platform=darwin arch=x64
•   packaging       platform=mas arch=x64   electron=6.1.7 appOutDir=dist/mas
• signing         file=dist/mas/AppName.app   identityName=3rd Party Mac Developer Application: TeamName (12345ABCDE)   identityHash=SOMELONGSTRING provisioningProfile=MacAppStore.provisionprofile

Some info from the Sqlite3 docs which may be relevant:

The sqlite3 module uses node-pre-gyp to download a pre-compiled binary for your platform, if it exists. Otherwise, it uses node-gyp to build the extension. It is also possible to make your own build of sqlite3 from its source instead of its npm package.

Relevant keys from the package.json file: I tried this with and without the postinstall script, and also tried setting buildDependenciesFromSource to true.

"dependencies": {
  "sqlite3": "^4.1.1"
},
"devDependencies": {
  "electron": "^6.1.7"
},
"scripts": {
  "postinstall": "electron-builder install-app-deps"
},
"build": {
  "appId": "com.domainname.appname",
  "mac": {
    "target": "mas",
    "hardenedRuntime": false,
    "gatekeeperAssess": false,
    "entitlements": "build/entitlements.mas.plist",
    "entitlementsInherit":   "build/entitlements.mas.inherit.plist",
    "provisioningProfile":   "MacAppStore.provisionprofile",
    "type": "distribution",
  }
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
steve981crcommented, Feb 2, 2020

Thanks, that works for distributing outside the Mac App Store if you also notarize the app and add hardened runtime entitlements of:

<key>com.apple.security.cs.allow-unsigned-executable-memory</key><true/>
<key>com.apple.security.cs.disable-library-validation</key><true/>

But to distribute the app through the Mac App Store the app needs to be sandboxed, meaning the app is self contained. For that you need to use the mas target and create a “provisioning profile” in your apple developer account.

@kzimny Are you intending to distribute your app on the mac app store? If so I’d be interested to know if you get the same errors I do.

And actually I found additional information since posting this issue. Adding:

"asarUnpack": [
  "**/*.node"
]

to the package.json file under the “mac” key will allow the signed sqlite binary file to be read by Apple. So that solved the signing issue. But I’m still not out of the woods. I’m now getting a new error, also from sqlite3, that crashes the app on launch. I’ve queried the Apple Developers forum. We’ll see what they have to say. Another point is this issue affects all node dependencies, not just Sqlite3. I tried it with other node dependencies and they throw the same error. Seems all the trouble started with Catalina OS, as they threw a bunch of new roadblocks up.

0reactions
xintengbaocommented, Feb 10, 2022

same issue, do you have solution?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Electron crashes when requiring sqlite3 native module in ...
I think the problem may be related to 'nativeness' of sqlite3 module, and I tried electron-rebuild , npm --build-from-source , they didn't help....
Read more >
app crash on start-up and a new created app is failing on ...
my existing app crash on app start-up with no errors, on newly created Xamarin. Forms the deployment is failing but build succeed.
Read more >
Local Database is not creating in NDK android app - SQLite
After migrating project to 64bit device (ABI: arm64-v8a) support, the application is crashing while creating local database in Android.
Read more >
Crashes - Android Developers
An Android app crashes whenever there's an unexpected exit caused by an unhandled exception or signal. An app that is written using Java...
Read more >
sqflite | Flutter Package - Pub.dev
Flutter plugin for SQLite, a self-contained, high-reliability, embedded, SQL database ... Simple flutter notepad working on iOS/Android/Windows/linux/Mac ...
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