Skip to content

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

@justfortherec

Description

@justfortherec

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions