native-client icon indicating copy to clipboard operation
native-client copied to clipboard

Error: Cannot find module '${HOME}/host.js'

Open justfortherec opened this issue 2 years ago • 0 comments

I am unable to connect Firefox with the native client because the path to host.js in the run.sh script is not found.

This is the error message that I see in the browser console:

NS_ERROR_ILLEGAL_VALUE: Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsINativeMessagingPortal.closeSession] [NativeMessaging.jsm:360](resource://gre/modules/NativeMessaging.jsm)
stderr output from native app com.add0n.node: node:internal/modules/cjs/loader:998
stderr output from native app com.add0n.node:   throw err;
stderr output from native app com.add0n.node:   ^
stderr output from native app com.add0n.node: 
stderr output from native app com.add0n.node: Error: Cannot find module '${HOME}/host.js'
stderr output from native app com.add0n.node:     at Module._resolveFilename (node:internal/modules/cjs/loader:995:15)
stderr output from native app com.add0n.node:     at Module._load (node:internal/modules/cjs/loader:841:27)
stderr output from native app com.add0n.node:     at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
stderr output from native app com.add0n.node:     at node:internal/main/run_main_module:23:47 {
stderr output from native app com.add0n.node:   code: 'MODULE_NOT_FOUND',
stderr output from native app com.add0n.node:   requireStack: []
stderr output from native app com.add0n.node: }
stderr output from native app com.add0n.node: 
stderr output from native app com.add0n.node: Node.js v18.12.1
OperationError: GDBus.Error:org.freedesktop.DBus.Error.UnknownMethod: Object does not exist at path “/org/freedesktop/portal/desktop/session/1_3947/firefox_com_add0n_node_4064532493”

(Note that I've replaced the actual path to my home directory with ${HOME} when copying the message)

It appears that Firefox starts the native client from $HOME as the working directory. That leads to the script resolving the relative path host.js as $HOME/host.js.

I was able to fix this by applying the following tiny patch to run.sh:

 #!/usr/bin/env bash
-/usr/bin/node host.js
+/usr/bin/node $(dirname "$0")/host.js

This prefixes the host.js filename with the directory of the run.sh file — regardless of the working directory and regardless of the directory in which run.sh and the JavaScript files are located (as long as they are in the same location).

justfortherec avatar Jan 06 '23 09:01 justfortherec