jehy / telegram-test-api

Simple implimentation of telegram API which can be used for testing telegram bots
MIT License
98 stars 24 forks source link

TypeError: TelegramServer is not a constructor #63

Closed olifur closed 2 years ago

olifur commented 2 years ago

Hi Devs,

Just starting out with the project and got my first error with the sample code from the website

$ node -v
v14.18.0
$ npm install telegram-test-api

following sample file: main.js

const TelegramServer = require('telegram-test-api');
let serverConfig = {port: 9000};
let server = new TelegramServer(serverConfig);
server.start();

running this code

$ node main.js 
/home/olifur/Git/bla/main.js:3
let server = new TelegramServer(serverConfig);
             ^

TypeError: TelegramServer is not a constructor
    at Object.<anonymous> (/home/olifur/Git/bla/main.js:3:14)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
    at internal/main/run_main_module.js:17:47

Something seems to be odd with the export / constructor of the TelegramServer class?

Thank you very much for your help Oli

olifur commented 2 years ago

Hi devs,

the last working version for me is 3.0.0, I tested it using:

for i in $(npm view telegram-test-api versions --json | grep '"' | sed 's#[", ]##g'); do rm -rf node_modules; echo $i; npm install telegram-test-api@$i; echo "const TelegramServer = require('telegram-test-api'); new TelegramServer();"  | node; done

everything > 3.0.0 produces the TypeError: TelegramServer is not a constructor error.

jehy commented 2 years ago

Hi! Fixed it in 4.1.3 version, it was an issue with default export in TypeScript.

olifur commented 2 years ago

Thank you very much!