I tired to run an terminal emulator / command prompt in NW.js using xterm JS and node-pty. I only get an DLL Error. The folling is the log:
Uncaught Error: Eine DLL-Initialisierungsroutine ist fehlgeschlagen.
\\?\C:\Users\volke.a\Z_local\nwjstart\node_modules\node-pty\build\Release\conpty.node
at Module._extensions..node (node:internal/modules/cjs/loader:1365:18) at Module.load (node:internal/modules/cjs/loader:1116:32)
at Module._load (node:internal/modules/cjs/loader:963:12)
at Module.require (node:internal/modules/cjs/loader:1140:19)
at require (node:internal/modules/helpers:117:18)
at new WindowsPtyAgent (C:\Users\volke.a\Z_local\nwjstart\node_modules\node-pty\lib\windowsPtyAgent.js:41:36)
at new WindowsTerminal (C:\Users\volke.a\Z_local\nwjstart\node_modules\node-pty\lib\windowsTerminal.js:51:24)
at Object.spawn (C:\Users\volke.a\Z_local\nwjstart\node_modules\node-pty\lib\index.js:29:12)
at chrome-extension://fnhkclelbagcndnlaobahcdeinlcloek/terminal.js:15:24
"Eine DLL-Initialisierungsroutine ist fehlgeschlagen" means "A DLL-Inizialationroutine failed".
My OS is Windows 10
This is the JavaScript code
const os = require('os');
const pty = require('node-pty');
const { Terminal } = require('xterm');
win = nw.Window.get()
win.x = 100
win.y = 100
// Create a new terminal instance
const terminalContainer = document.getElementById('terminal');
const term = new Terminal();
term.open(terminalContainer);
// Start a PowerShell terminal session using node-pty
const shell = os.platform() === 'win32' ? 'powershell.exe' : 'bash';
const ptyProcess = pty.spawn(shell, [], {
name: 'xterm-color',
cols: 80,
rows: 30,
cwd: process.cwd(),
env: process.env
});
// Pipe terminal output to xterm.js
ptyProcess.onData(data => term.write(data));
term.onData(data => ptyProcess.write(data));
// Handle command line input
term.onKey(e => {
const printable = !e.domEvent.altKey && !e.domEvent.ctrlKey && !e.domEvent.metaKey;
if (e.domEvent.keyCode === 13) {
ptyProcess.write('\r\n');
} else if (printable) {
ptyProcess.write(e.key);
}
});
I already tried to update npm, node, node-pty, xterm and NW.js.
Your dependencies need to be built/compiled for the version of Node.js included in the NW.js build you're using.
See the node-pty README discussing this: https://github.com/microsoft/node-pty#dependencies
And the NW.js docs: https://nwjs.readthedocs.io/en/latest/For%20Users/Advanced/Use%20Native%20Node%20Modules/
And an easy way to match versions: https://nwjs.io/versions.json