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.

Assessment

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

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.

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

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

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

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.

More from steelbrain/node-ssh

All issues in steelbrain/node-ssh

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.