Building and utilizing xterm.js on your local machine - A step-by-step guide

I have been attempting to modify the source code of xterm.js and test my changes before submitting a PR. Unfortunately, I have not been able to generate a functional 'distribution.'

(I apologize if my terminology is incorrect -- I am still fairly new to web development)

Setup

I have set up a basic test website with the following index.html

<!doctype html>
  <html>
    <head>
      <script src="%PUBLIC_URL%/xterm.js"></script>
    </head>
    <body>
      <div id="terminal"></div>
      <script>
        console.log(Terminal);
        var term = new Terminal();
        term.open(document.getElementById('terminal'));
        term.write('Hello from \x1B[1;3;31mxterm.js\x1B[0m $ ')
      </script>
    </body>
  </html>

In place of %PUBLIC_URL%, I intend to include a JS source file xterm.js from either of the following locations:

  • node_modules/xterm/dist/xterm.js - added through npm
  • xterm.js/lib/xterm.js - built from the GitHub repository

To build a local version of xterm.js, I followed these steps:

git clone https://github.com/xtermjs/xterm.js.git xterm-local
cd xterm-local
npm install
npm run package

(Please note: I encountered difficulties building xterm.js on Windows or Mac -- I only succeeded on Ubuntu 18.04)

All the commands ran successfully, and the last one generated xterm-local/lib which includes xterm.js. I utilized this file to replace the copy obtained from the NPM installation.

Results

With NPM Distribution

Using the NPM dist/xterm.js, I managed to render my terminal element with the log displaying:

ƒ Terminal(options) {
        this._core = new Terminal_1.Terminal(options);
        this._addonManager = new AddonManager_1.AddonManager();
    }

With Local Build

However, when utilizing my locally built output from xterm-local/lib/xterm.js, the terminal element was not rendered, and I encountered an error:

Uncaught TypeError: Terminal is not a constructor
. The log displayed:

{Terminal: ƒ, __esModule: true}
  Terminal: ƒ e(e)
  __esModule: true
  __proto__: Object

Expectations

After building my local version of xterm.js, I anticipated being able to use it interchangeably with the NPM distribution. However, I am curious as to why the command npm run package did not generate the dist folder but a lib folder instead. Are there further steps that I am overlooking in order to create a functional copy of xterm.js?

Answer №1

I have come up with a partly acceptable solution, and I'm eager to share my findings.

This Isn't the Demonstration You Seek

Credit goes to user Peter for guiding me to xterm.js' wiki page on contributing (not to be confused with the CONTRIBUTING.md file in the repository). It was a bit challenging to locate because, to a newcomer, a line in the repo's CONTRIBUTING.md document seemed to point to the demo found on xtermjs.org with the following simple instructions:

Get the xterm.js demo running.

However, that was not the case. It actually refers to running the demo application located in xterm.js/demo.

Executing the Genuine Demo

The developers of xterm.js are more experienced than I am. They have provided numerous methods to build and run the demo, which can be overwhelming. Eventually, the SourceLair option worked for me, despite my reluctance to provide my credit card information.

Start by forking the xterm.js repository - this is crucial as you'll want to make changes to the source code!

The 'shortcut' provided at isn't very helpful. Instead, head to SourceLair, create a new project based on your own fork of xterm.js, and select the 'Node' environment preset. This will enable you to test your modifications (using the web server tool) and save your changes (by using your fork instead of the upstream repository).

  • Go to SourceLair
  • Start a new project by cloning a repository
  • Provide your repository URL
  • Allow for initialization (git clone, yarn install, webkit compilation, etc.)
  • Create a new branch for your changes (in the Terminal
    git checkout -b [name_of_your_new_branch]
    )
  • Implement your changes
  • Test them out using the Public URL of the project
  • Commit and push your changes back to your repository

(If you prefer not to use web editors, you can make changes to your repository and pull them into SourceLair for testing.)

Difficulties with Alternative Methods

Just a heads-up.

  • Docker: It was simple to utilize the pre-configured image, but making necessary changes from within the container was challenging.
  • Foreman (Procfile runners): Unfamiliar with them and pressed for time (remember, this is a hobby!)
  • Linux / MacOSX: On Linux, I could build but not test (my only Linux is a VPS that I SSH into) and on Mac, I could potentially test but not build due to the node-gyp dependency failing at the time of writing.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unable to configure node and express for file serving

Currently using Windows 7, I have successfully installed nodes 0.10.12 and the latest versions of express and express-generator globally. I then proceeded to create a new express project called nodetest1 and installed all dependencies using npm install. U ...

Enhance Bootstrap modals by automatically adjusting the background shadow mask when resizing or changing the content within the modal window

Incorporated within my bootstrap modal window is a form alongside a link that triggers the jQuery functionality of .slideToggle(). By interacting with this link, a concealed div expands. Consequently, the size of the modal popover becomes fluid. Upon click ...

What steps are needed to pass an additional parameter to the onMouseDown function in ReactJS?

The TypeScript function listed below demonstrates the functionality: const handleMouseDownHome = (e: any) => { // Only activates when scroll mouse button is clicked if (e.button === 1) { window.open("/", "_blank", " ...

Creating an array of strings using data from a separate array of objects in JavaScript/TypeScript

I want to generate a new array of strings based on an existing array of objects, with each object belonging to the Employee class and having a firstName field: assignees: Array<Employee>; options: string[]; I attempted to achieve this using the fol ...

Fix image that won't load in Firefox

My website features an <img /> element that initially lacks a src attribute. The src is added dynamically using JavaScript at a later point. While Chrome hides it, Firefox displays an empty space: https://i.sstatic.net/3eZJ4.png Is there a way to p ...

Vorlon.js is requesting Socket.io, even though its configuration already includes socket.io

Whenever I try to load the app, a red div appears in front with the message: Vorlon.js: make sure to load socket.io before referencing vorlon.js or set includeSocketIO = true in your catalog.json file. Every time I access the server page, my terminal d ...

Error with Firebase on Apple's M1 Mac devices

I recently upgraded my MacBook Air to the M1 chip. Firebase was functioning properly until I updated firebase-tools from version 9.7.0 to 9.8.0 last week. Since the update, I encounter an error anytime I attempt to execute a "firebase" command. This quest ...

Install a package by using the npm command within a node container

After following the steps outlined in the node.js documentation to create a Dockerfile, I attempted to run the command docker exec -it mynodeapp /bin/bash with the intention of entering the container to install a new npm package. However, I encountered the ...

Error: The attempt to access the 'useContext' property of null has failed due to a TypeError

Nowhere in my React code am I using the useContext property. There is a compiled webpack file in an npm package with a component inside. When trying to use this component in my React app, it throws an error: Uncaught TypeError: Cannot read properties of nu ...

Repetitive use of multiple submit buttons in AngularJS

i'm currently working with AngularJS Currently facing this issue: view screenshot I have utilized the following HTML code to display submit button for two different types of forms. One for TEXT Form and one for ENUM Form: <div ng-controller="g ...

every cell should be painted a distinct hue

I need to create a 10x10 array in JavaScript and fill each cell in the 2D array with different colors using canvas. I have managed to do this part, but now I am stuck on how to check if each cell has a different color from its neighbors. Any suggestions ...

What is the best way to pass values between JSP Expression Language and Javascript?

I have a request object with the following content: List<Integer> list What is the best way to loop through this list using JavaScript? I am interested in obtaining the values of each element within the list. Note that these list values are not cu ...

Tips for utilizing window.scrollTo in tandem with react/material UI?

I have a simple functional component that displays an alert panel with an error message under certain conditions. The issue I am facing is that when the alert panel is rendered due to an error, it might be off-screen if the user has scrolled down. To addre ...

Harnessing the power of Promise to verify the completion of a filestream

After initializing the variables below, I update them while parsing through a large CSV file, which can be time-consuming. var yearTotal2008 = 0; var year2008TallyByPatient = {}; To process the CSV file, I use the following function: const produceChart ...

Node JS does not receive a response from JQuery Ajax

I have developed a form on the client side which includes: <html> <body> <script> $(document).ready(function() { $.ajax({ url: "Search.html", type: "POST", dataType : "json", s ...

The form validation in Bootstrap 5 seems to be having some trouble triggering

Here is the form setup for allowing users to change their account password: <div class="signup-form-small"> <form method="post" name="frmPassword" id="frmPasswo ...

Node.js and Express constantly face the challenge of Mongoose connecting and disconnecting abruptly

I have been running an Express (Node.js) app connected to MongoDB using Mongoose for a while now. Everything was working smoothly until recently, when it started acting up. It appears that the server is establishing a connection with MongoDB only to disco ...

Displaying live IP CAMERA feed using three.js

I am currently facing a challenge in rendering a video stream from an IP Camera to a three.js texture. I have attempted the following code snippet without success: .... var video = document.createElement('video'); video.crossOrigin="anonymous" ...

Can I use more than one AudioContext at a time?

In my project, I am developing a React App using MeteorJS that utilizes the Web Audio API. This app consists of multiple pages, each of which utilizes web audio functionality. The issue I am facing is that I have hit the limit of 6 audio contexts allowed i ...

Using jQuery to create a flawless animation

I am currently working on an animation project, and I have shared my progress on jsfiddle. Below is the code snippet I have utilized: /* JavaScript: */ var app = function () { var self = this; var allBoxes = $('.box&apos ...