1

On electron, the node module vosk needs to access some shared objects located in node_modules/vosk/lib/.

The issue I am having right now is that, when I do require('vosk') in my main.js and try to execute my AppImage file, I get:

A JavaScript error occurred in the main process
Uncaught Exception:
Error: Dynamic Linking Error: /tmp/.mount_CantooClaxGf/resources/app.asar/node_modules/vosk/lib/linux-x86_64/libvosk.so: Cannot open the shared object: It's not a folder
    at new DynamicLibrary (/tmp/.mount_CantooClaxGf/resources/app.asar/node_modules/ffi-napi/lib/dynamic_library.js:75:11)
    at Object.Library (/tmp/.mount_CantooClaxGf/resources/app.asar/node_modules/ffi-napi/lib/library.js:47:10)
    at Object.<anonymous> (/tmp/.mount_CantooClaxGf/resources/app.asar/node_modules/vosk/index.js:24:21)
    at Module._compile (internal/modules/cjs/loader.js:1145:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1166:10)
    at Module.load (internal/modules/cjs/loader.js:981:32)
    at Module._load (internal/modules/cjs/loader.js:881:14)
    at Function.Module._load (electron/js2c/asar.js:769:28)
    at Module.require (internal/modules/cjs/loader.js:1023:19)
    at require (internal/modules/cjs/helpers.js:77:18)

I tried to add vosk to the files in the build:

 "build": {
    "files": [
      "dist/**/*",
      "src/assets/icons/*",
      "electron.js",
      "package.json",
      "assets/models/*",
      "node_modules/vosk/lib/*"
    ],

I can now see the files in the app.asar.unpacked/node_modules/vosk/lib/ folder, but when executing the app, I'm still having the same error.

I found this answer mentioning a hack, but it didn't solve my issue and I still have the exact same error.

How am I supposed to package the shared objects in a way that vosk will find them?

Sharcoux
  • 5,546
  • 7
  • 45
  • 78

2 Answers2

0

I could solve the issue with this config for electron, putting all the dependencies of vosk in the extraResources field:

  "build": {
    "extraResources": [
      "node_modules/at-least-node/**/*",
      "node_modules/builder-util-runtime/**/*",
      "node_modules/debug/**/*",
      "node_modules/ffi-napi/**/*",
      "node_modules/fs-extra/**/*",
      "node_modules/get-symbol-from-current-process-h/**/*",
      "node_modules/get-uv-event-loop-napi-h/**/*",
      "node_modules/graceful-fs/**/*",
      "node_modules/jsonfile/**/*",
      "node_modules/ms/**/*",
      "node_modules/node-addon-api/**/*",
      "node_modules/node-gyp-build/**/*",
      "node_modules/ref-napi/**/*",
      "node_modules/ref-struct-di/**/*",
      "node_modules/sax/**/*",
      "node_modules/universalify/**/*",
      "assets/models/**/*"
    ],
    "files": [
      "dist/**/*",
      "src/assets/icons/*",
      "electron.js",
      "package.json"
    ],

I also needed this lib.

It's now working as expected

Sharcoux
  • 5,546
  • 7
  • 45
  • 78
0

I solved by updating my electron-builder configuration in package.json to be

{
  "build": {
    "asar": true,
    "asarUnpack": [
      "node_modules"
    ],
  }
}

Then ensuring the unpacked path was used instead:

var dirPath = __dirname.includes('.asar') ? __dirname.replace('.asar', '.asar.unpacked') : __dirname;
Kim T
  • 5,770
  • 1
  • 52
  • 79