I want to use xterm in NodeJS app but it doesn't work. I am using node version v16.15.0, npm version v8.5.5, xterm version 4.18.0.
In documentation (https://github.com/xtermjs/xterm.js), it says importing is made by writing new ES6 syntax with import Terminal from 'xterm';
. I am also adding "type": "module"
into package.json, but I am getting: ReferenceError: self is not defined
showing some line in xterm.js
.
My source code:
import Terminal from 'xterm';
const path = require('path')
const express = require('express')
const dotenv = require('dotenv')
const morgan = require('morgan')
const exphbs = require('express-handlebars')
const session = require('express-session')
const WebSocket = require('ws')
const wss_dashboard = new WebSocket.Server({ port: 7070 })
my package.json:
{
...
"type": "module",
...
}
How can I fix that?
CodePudding user response:
You should try reloading your Node.js server and run the file again.
Adding "type": "module" to the package.json worked for me.
Also try adding {} tho the import:
import { Terminal } from 'xterm';
CodePudding user response:
Your import is not correct
Should be
import { Terminal } from 'xterm';
Not
import Terminal from 'xterm';