TypeError: Class constructor EventEmitter cannot be invoked without 'new'

50 Views Asked by At

I'm developing a small twitch connector, and I'm facing a major error: This is the following error:

BasicPubSubClient.js:25
        var _this = _super.call(this) || this;
                           ^

TypeError: Class constructor EventEmitter cannot be invoked without 'new'

I'm doing the imports as follows:

import {PubSubClient} from 'twitch-pubsub-client';
import {ApiClient} from 'twitch';
import {StaticAuthProvider} from 'twitch-auth';

And calling the method:

class pubSubClientHandler {
    constructor() {
    --> this.pubSubClient = new PubSubClient(); <---
        this.authProvider = new StaticAuthProvider(process.env.TWITCH_CLIENT_ID, process.env.TWITCH_ACCESS_TOKEN);
        this.apiClient = new ApiClient({ authProvider: this.authProvider });
    }

This is my package.json.

{
  "name": "starter-express-api",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build": "rimraf dist/ && babel ./ --out-dir dist/ --ignore ./node_modules,./.babelrc,./package.json,./npm-debug.log --copy-files",
    "start": "npm run build && node dist/index.js"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/cyclic-software/starter-express-api.git"
  },
  "author": "Pedro Azevedo",
  "license": "ISC",
  "type": "commonjs",
  "bugs": {
    "url": "https://github.com/cyclic-software/starter-express-api/issues"
  },
  "homepage": "https://github.com/cyclic-software/starter-express-api#readme",
  "dependencies": {
    "@babel/runtime": "^7.23.8",
    "core-js": "^3.35.1",
    "cron": "^3.1.6",
    "ejs": "^3.1.9",
    "express": "^4.18.2",
    "express-ws": "^5.0.2",
    "openai": "^4.20.1",
    "promisify": "^0.0.3",
    "regenerator-runtime": "^0.14.1",
    "request": "^2.88.2",
    "say": "^0.16.0",
    "sound-play": "^1.1.0",
    "tmi.js": "^1.8.5",
    "twitch": "^4.6.7",
    "twitch-auth": "^4.6.7",
    "twitch-pubsub-client": "^4.6.7",
    "ws": "^8.14.2"
  },
  "engines": {
    "node": ">=14.0.0"
  },
  "devDependencies": {
    "@babel/cli": "^7.23.4",
    "@babel/core": "^7.23.7",
    "@babel/plugin-proposal-class-properties": "^7.18.6",
    "@babel/plugin-transform-runtime": "^7.23.7",
    "@babel/preset-env": "^7.23.8",
    "babel-loader": "^9.1.3",
    "rimraf": "^5.0.5"
  }
}

And my .babelrc

{
  "presets": [
    [
      "@babel/preset-env",
      {"targets": {"esmodules": true}}
    ]
  ],
  "plugins": [
    "@babel/plugin-proposal-class-properties"
  ]
}

How can I fix this error?

Thank you.

0

There are 0 best solutions below