Skip to content

I have a question about my error: this._ptyNative.startProcess is not a function #749

Description

Environment details

  • OS: Windows
  • OS version: windows 10
  • node-pty version: v1.0.0
  • node version: v18.20.4

Issue description

I'm making a plugin for obsidian, and I have the following error when running it.

plugin:sample-plugin:8124 TypeError: this._ptyNative.startProcess is not a function
    at new WindowsPtyAgent2 (plugin:sample-plugin:7252:36)
    at new WindowsTerminal2 (plugin:sample-plugin:7557:26)
    at spawn2 (plugin:sample-plugin:7988:14)
    at new ExampleView (plugin:sample-plugin:8120:51)
    at eval (plugin:sample-plugin:8165:17)
    at t.<anonymous> (app.js:1:2113665)
    at app.js:1:237228
    at Object.next (app.js:1:237333)
    at app.js:1:236249
    at new Promise (<anonymous>)

Here is the code I implemented:

import { ItemView, WorkspaceLeaf } from 'obsidian';
import { Terminal } from '@xterm/xterm';
import { IPty, spawn } from 'node-pty';
import '@xterm/xterm/css/xterm.css';

export const VIEW_TYPE_EXAMPLE = 'example-view';
export class ExampleView extends ItemView {

  term: Terminal;
  ptyProcess: IPty;

  constructor(leaf: WorkspaceLeaf) {
    super(leaf);
    try {
      this.ptyProcess = spawn('cmd.exe', [], {
        name: 'xterm-color'
      });
    } catch (error) {
      console.error(error)
    }
    this.term = new Terminal();
  }

  getViewType() {
    return VIEW_TYPE_EXAMPLE;
  }

  getDisplayText() {
    return 'Example view';
  }

  async onOpen() {
    const contentEl = this.containerEl.children[1].createDiv({ cls: 'html-terminal' });
    this.term.open(contentEl);
    this.term.writeln('Welcome from \x1B[1;3;31mxterm.js\x1B[0m');
    this.term.write(' $ ');

    try {
      this.term.onData(data => {
        try {
          this.ptyProcess?.write(data);
        } catch (err) {
          console.error('Error writing to pty:', err);
        }
      });

      this.ptyProcess.onData(data => {
        this.term.write(data);
      });

    } catch (err) {
      console.error(err);
    }
  }

}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions