Running into error when importing xterm.js in node.js

Viewed 107

I am new to node.js, I am trying to run some node.js code from here:

https://xtermjs.org/docs/api/addons/attach/

I got an error:

(node:1576) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.

So I renamed the file to .mjs, and I got an error:

import { Terminal } from 'xterm';
         ^^^^^^^^
SyntaxError: Named export 'Terminal' not found. The requested module 'xterm' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'xterm';
const { Terminal } = pkg;

I followed its suggestion but it just printed a bunch of source code and then error: ReferenceError: self is not defined

What is the right way to do it?

0 Answers
Related