steelbrain / steelbrain/node-ssh

When used on the renderer process of the Electron environment, the message "Class constructor NodeSSH cannot be invoked without 'new'" is displayed and instantiation fail.

Open
#427 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
1k
Forks
94
PR merge metrics
No merged PRs in 30d

Description

Hello.

I am considering the use of NodeSSH in the Electron environment.
I made the NodeSSH module available on the renderer process using a preload mechanism in order to reflect the processing result on the screen.

// main.js
const { app, BrowserWindow } = require('electron')
const path = require("path");

let win
function createWindow() {
  win = new BrowserWindow({
    width: 400,
    height: 400,
    webPreferences: {
      nodeIntegration: true, 
      preload: path.join(__dirname, './src/preload.js'),
      contextIsolation: true,
    }
  });
  // ...
}
app.on('ready', () => {
  createWindow();
})
// preload.js
const { contextBridge, ipcRenderer} = require("electron");
contextBridge.exposeInMainWorld(
  "requires", {
    nodessh : require('node-ssh'),
    ipcRenderer : ipcRenderer,
  }
);
// index.js(In RendererProcess)
const {NodeSSH} = window.requires.nodessh;
const ssh = new NodeSSH();
// ...

In this way, electron execution itself is possible, but on the second line of the index .js, an error of "Class constructor NodeSSH cannot be invoked without 'new'" occurs and the script stops executing.

When I checked in electron's developer console, the value of "window.requires.nodessh" seems to be "{SSHError: ƒ, NodeSSH: ƒ}", and I think the loading itself is successful, but is there any missing description?


Environment

Windows 11 Pro
Version 21H2 Build: 22000.613

npm -v

8.4.1

.\node_modules.bin\electron -v

v18.1.0

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the failure using main.js, preload.js, and index.js with Electron v18.1.0, then inspect how window.requires.nodessh is exposed and instantiated in the renderer process. Done means the reported NodeSSH instantiation error no longer occurs in this Electron setup.

Written by the indexing model from the issue text.

Assessment

Tech stack
electron, javascript
Domain
desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.