electron-builder: Cannot find module napi-v6-darwin-unknown-x64 in the universal app

  • Electron-Builder Version: 24.0.0
  • Node Version: 16.15.1
  • Electron Version:23.1.3
  • Electron Type (current, beta, nightly): current
  • Target: Universal
  • I’m trying to build our Electron app as a Universal (I’m using this command electron-builder --config ./electron-builder.json --mac --universal), but I got this error in the run time for the app after building it from the M1 machine with XCode v14.2 (I’m using sqlite3 v5.1.4)
An unexpected error occurred at startup

09/03/2023, 17:06:04 EET Error details: 
name: Error,
message: Cannot find module '/Applications/myApp.app/Contents/Resources/app-x64.asar/node_modules/sqlite3/lib/binding/napi-v6-darwin-unknown-x64/node_sqlite3.node'
Require stack:
- /Applications/myApp.app/Contents/Resources/app-x64.asar/node_modules/sqlite3/lib/sqlite3-binding.js
- /Applications/myApp.app/Contents/Resources/app-x64.asar/node_modules/sqlite3/lib/sqlite3.js
- /Applications/myApp.app/Contents/Resources/app-x64.asar/dist/main-bundle.js
- /Applications/myApp.app/Contents/Resources/app.asar/index.js
- ,

  • Here is myApp.app/Contents/Resources directory in the Application path Screenshot 2023-03-09 170831

  • As you see there is no napi-v6-darwin-unknown-x64 inside app-x64.asar.unpacked while there is napi-v{napi_build_version}-darwin-unknown-x64

  • When I tried to build the app from an Intel machine (Xcode v14.2) there is napi-v6-darwin-unknown-x64 inside app-x64.asar.unpacked while there is no napi-v6-darwin-unknown-arm64 inside app-arm64.asar.unpacked(napi-v{napi_build_version}-darwin-unknown-arm64 exists)

  • Here is electron-builder.json contents:

{
  "appId": "com.myapp.myApp",
  "productName": "mayApp",
  "buildVersion": "2.1.0",
  "compression": "normal",
  "directories": {
    "app": "./rb-services",
    "buildResources": "./setup/build",
    "output": "./compile"
  },
  "afterSign": "./notarize.js",
  "asarUnpack": ["**/*.node"],
  "mac": {
    "category": "public.app-category.business",
    "icon": "./setup/build/icon.icns",
    "hardenedRuntime": true,
    "mergeASARs": false,
    "entitlements": "./setup/build/entitlements.mac.plist",
    "entitlementsInherit": "./setup/build/entitlements.mac.plist",
    "files": [
      "**/*",
      "!**/*.ts",
      "!**/*.tlog",
      "!**/*.log",
      "!**/*.exp",
      "!**/*.lib",
      "!**/*.iobj",
      "!**/*.obj",
      "!**/*.ipdb",
      "!**/*.pdb",
      "!**/*.ilk",
      "!**/*.map",
      "!**/*.vcxproj*",
      "!**/*.lastbuildstate",
      "!**/*config.gypi",
      "!**/*binding.gyp",
      "!**/*Dockerfile",
      "!**/*tsconfig.json",
      "!**/patches/*.patch",
      "!**/node_modules/**/*/doc/**/*",
      "!**/node_modules/**/*/docs/**/*",
      "!**/node_modules/sqlite3/build/**/*",
      "!**/node_modules/sqlite3/build-tmp-napi-v6/**/*",
      "!**/node_modules/**/*.{mk,a,o,h}",
      "!src"
    ],
  "dmg": {
    "title": "mayApp",
    "background": "./setup/build/myApp.png",
    "iconSize": 90,
    "contents": [
      { "x": 448, "y": 300, "type": "link", "path": "/Applications" },
      { "x": 192, "y": 300, "type": "file" }
    ],
    "window": {
      "height": 500
    }
  }, 
  "appx": {
    "publisherDisplayName": "myApp"
  },
  "electronVersion": "23.1.3",
  "buildDependenciesFromSource": true,
  "nodeGypRebuild": false,
  "npmRebuild": true,
  "extends": null
}

** Update: The issue doesn’t exist when using electron-builder v23.6.0, it seems related to the latest version (24.0.0)

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 1
  • Comments: 22

Most upvoted comments

Updated @electron/rebuild dependency so that you don’t need to use a custom patch-package approach. electron-builder 24.3.0 has the fix

Wait, why is it not leveraging build/Release/node_sqlite3.node in each of the relative unpacked asars?

~/D/electron-builder-test> ls **/*.node
  app-arm64.asar.unpacked/node_modules/sqlite3/bin/darwin-arm64-110/sqlite3.node
  app-arm64.asar.unpacked/node_modules/sqlite3/bin/darwin-x64-110/sqlite3.node
  app-arm64.asar.unpacked/node_modules/sqlite3/build/Release/node_sqlite3.node
  app-arm64.asar.unpacked/node_modules/sqlite3/lib/binding/napi-v6-darwin-unknown-arm64/node_sqlite3.node
  app-arm64.asar.unpacked/node_modules/sqlite3/lib/binding/napi-v{napi_build_version}-darwin-unknown-arm64/node_sqlite3.node
  app-arm64.asar.unpacked/node_modules/sqlite3/lib/binding/napi-v{napi_build_version}-darwin-unknown-x64/node_sqlite3.node
  app-x64.asar.unpacked/node_modules/sqlite3/bin/darwin-x64-110/sqlite3.node
  app-x64.asar.unpacked/node_modules/sqlite3/build/Release/node_sqlite3.node
  app-x64.asar.unpacked/node_modules/sqlite3/lib/binding/napi-v6-darwin-unknown-arm64/node_sqlite3.node
  app-x64.asar.unpacked/node_modules/sqlite3/lib/binding/napi-v{napi_build_version}-darwin-unknown-x64/node_sqlite3.node

.{mk,a,o,h}

I think the extensions “.mk”, “.a”, “.o”, and “.h” are used for make files, static libraries, object files, and header files, respectively. Each of these file types serves a specific purpose in the process of compiling and linking source code, but as I saw no need to be in the generated app (at least in my project),

• executing @electron/rebuild appDir=/Users/omaralfroukh/Desktop/Test projects/electron-quick-startt/electron-quick-start arch=x64 clang: error: no such file or directory: ‘projects/electron-quick-startt/electron-quick-start/node_modules/sqlite3/node_modules/node-addon-api’ make:

I guess electron/rebuild or make doesn’t handle paths with spaces? Try removing the empty space from Test projects and replace with hypen?

I can prob take a look at the repro repo later today or this weekend.