How to handle system-uri-response in the main.js process


Using my previous simple example, packaging with pkg:

$ pkg --targets host index.js
> pkg@4.3.1

Gives the following result upon execution:

$ index.exe
ERROR:  Error: Dynamic Linking Error: Win32 error 126
    at new DynamicLibrary (C:\snapshot\test\node_modules\ffi\lib\dynamic_library.js:74:11)
    at Object.DynamicLibrary (C:\snapshot\test\node_modules\ffi\lib\dynamic_library.js:33:12)
    at Object.ffi.init (C:\snapshot\test\node_modules\@maidsafe\safe-node-app\src\native\lib.js:20:15)
    at new SAFEApp (C:\snapshot\test\node_modules\@maidsafe\safe-node-app\src\app.js:36:9)
    at Object.initializeApp (C:\snapshot\test\node_modules\@maidsafe\safe-node-app\src\index.js:61:25)
    at authorise (C:\snapshot\test\index.js:0:0)
    at __dirname (C:\snapshot\test\index.js:0:0)
    at Object.<anonymous> (C:\snapshot\test\index.js:0:0)
    at Module._compile (pkg/prelude/bootstrap.js:1243:22)
    at Object.Module._extensions..js (module.js:644:10)
(node:15456) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): Failed to load native libraries: Error: Dynamic Linking Error: Win32 error 126
(node:15456) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero
exit code.

Error 126 means the library is not found.

I figured out that we can give an option to initializeApp and fromAuthURI to specify the path to append to the library searching: libPath. So, the following worked out well:

const path = require('path');

// ...

const app = await safeApp.initializeApp(info, null, {
    libPath: path.join(path.dirname(process.execPath), './node_modules/@maidsafe/safe-node-app/src/native')

This will be put together with the name of the library (src/native/lib.js#L33) and it will be found. (Assuming relative to the executable the node_modules directory is located containing the built @maidsafe/safe-app-node package with its libraries.)

I think I’ll be refining this to make some kind of repository that will use any of this to make a packagable test app.


Bravo @bzee. I just tested this and it seems to work! I have a command which just invoked SAFE Browser! Woohooo.

The packaged executable is 44MB just to do that, but it damn well works.

I’ve only tested Linux BTW, but pkg also works for Windows and Mac so easy to check this out too.


This topic was automatically closed after 60 days. New replies are no longer allowed.