-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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. #427
Comments
Hello! This is quite an interesting bug you're hitting. If I had to guess, it'a a bundler messing things up somewhere. Can you please post the output of the code below?
|
Thanks for the reply.
Also, if I check the NodeSSH value from the console, it looks like this:
The value of
Did it become a clue? |
Aha! That explains it! It's a limitation in the Electron code proxy. You'll have to work it around. Instead of exporting |
Thanks for the reply. The code was changed as follows and the process was performed. // preload.js
const { contextBridge, ipcRenderer} = require("electron");
const { NodeSSH } = require("node-ssh"); // changed
contextBridge.exposeInMainWorld(
"requires", {
getNodeSSH: function (opts) { return new NodeSSH(opts) }, // changed
ipcRenderer : ipcRenderer,
}
); // index.js(In RendererProcess)
const ssh = window.requires.getNodeSSH(); // changed
ssh.connect({...}); // changed However, the following error prevents the SSH connection.
When I checked the ssh variable, it seems to be reading it because it says In addition, it was confirmed that the desired processing can be executed when SSH connection is performed in the main process using ipcRenderer. |
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.
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
The text was updated successfully, but these errors were encountered: