question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Create a node.js target for xterm.js

See original GitHub issue

Details

  • OS version: node
  • xterm.js version: 4.4.0
> require('xterm')
Thrown:
ReferenceError: window is not defined
    at Object.<anonymous> (/private/tmp/test/node_modules/xterm/lib/xterm.js:1:224)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)

Steps to reproduce

https://runkit.com/embed/q7w97d0b8wj2

Looks like webpack4 bug, See: https://medium.com/@JakeXiao/window-is-undefined-in-umd-library-output-for-webpack4-858af1b881df

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:24 (23 by maintainers)

github_iconTop GitHub Comments

2reactions
Tyriarcommented, Apr 26, 2020

Good progress has been made on this. I’m not sure just yet how we’ll end up publishing the module though as ./package.json in the root is xterm and points at typing/xterm.d.ts. I want to be able to publish xterm-core with a totally separate set of typings, readme and package.json while at the same time don’t really want to include that in the src/ directory.

2reactions
the21stcommented, Mar 12, 2020

I’d also love it if xterm supported node. I originally thought node is supported, since xterm can already run in “headless” mode: https://github.com/xtermjs/xterm.js/issues/266 , without being attached to a DOM.

I tried a simple workaround in my code, just setting global.window = undefined before require('xterm') and that fixed the ReferenceError and everything is working as expected. It’s just a pain to have to set that everywhere, including in tests.

Awesome work on xterm by the way 🙂

Edit: this is what got me to think Node.js should work 🙂 https://github.com/xtermjs/xterm.js/blob/master/src/Terminal.ts#L70-L71 :

// Let it work inside Node.js for automated testing purposes.
const document = (typeof window !== 'undefined') ? window.document : null;
Read more comments on GitHub >

github_iconTop Results From Across the Web

It's possible to xterm.js on nodejs server side? - Stack Overflow
I'm creating a mutiplex terminal on NodeJs, for rendering data to StdOut i'm using terminal.js, but it is a little bit glitchie, ...
Read more >
Creating A Browser-based Interactive Terminal (Using ...
Creating A Browser-based Interactive Terminal (Using XtermJS And NodeJS). Why a terminal in the browser? A browser-based terminal has a lot of use...
Read more >
billchurch/webssh2: Web SSH Client using ssh2, socket.io ...
Web SSH Client using ssh2, socket.io, xterm.js, and express. A bare bones example of an HTML5 web-based terminal emulator and SSH client.
Read more >
Setting up a Go backend for Xterm.js to get a shell over the ...
In terms of steps, I needed to build the binary, pull in dependencies for the frontend, and get artifacts from both the previous...
Read more >
Process | Node.js v19.3.0 Documentation
Normally, the Node.js process will exit when there is no work scheduled, but a listener registered on the 'beforeExit' event can make asynchronous...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found