yagop / node-telegram-bot-api

Telegram Bot API for NodeJS
MIT License
8.13k stars 1.49k forks source link

No bun.js support #1120

Closed Elektroplayer closed 8 months ago

Elektroplayer commented 10 months ago

Bug Report

I have read:

I am using the latest version of the library.

I am start this code with bun 1.0.0.

import TelegramBot from "node-telegram-bot-api";

const bot = new TelegramBot(process.env.TOKEN, { polling: true });

Expected Behavior

Bot starts

Actual Behavior

Bot not starts with this error:

> bun .
[0.05ms] ".env"
1 | (function (process,nextTickQueue,drainMicrotasksFn,reportUncaughtExceptionFn){"use strict";var queue,process,nextTickQueue=nextTickQueue,drainMicrotasks=drainMicrotasksFn,reportUncaughtException=reportUncaughtExceptionFn;function validateFunction(cb){if(typeof cb!=="function"){const err=@makeTypeError(`The "callback" argument must be of type "function". Received type ${typeof cb}`);throw err.code="ERR_INVALID_ARG_TYPE",err}}var setup=()=>{queue=function createQueue(){class FixedCircularBuffer{constructor(){this.bottom=0,this.top=0,this.list=@newArrayWithSize(2048),this.next=null}isEmpty(){return this.top===this.bottom}isFull(){return(this.top+1&2047)===this.bottom}push(data){this.list[this.top]=data,this.top=this.top+1&2047}shift(){var{list,bottom}=this;const nextItem=list[bottom];if(nextItem===@undefined)return null;return list[bottom]=@undefined,this.bottom=bottom+1&2047,nextItem}}class FixedQueue{constructor(){this.head=this.tail=new FixedCircularBuffer}isEmpty(){return this.head.isEmpty()}push(data){if(this.head.isFull())this.head=this.head.next=new FixedCircularBuffer;this.head.push(data)}shift(){const tail=this.tail,next=tail.shift();if(tail.isEmpty()&&tail.next!==null)this.tail=tail.next,tail.next=null;return next}}return new FixedQueue}();function processTicksAndRejections(){var tock;do{while((tock=queue.shift())!==null){var{callback,args,frame}=tock,restore=@getInternalField(@asyncContext,0);@putInternalField(@asyncContext,0,frame);try{if(args===@undefined)callback();else switch(args.length){case 1:callback(args[0]);break;case 2:callback(args[0],args[1]);break;case 3:callback(args[0],args[1],args[2]);break;case 4:callback(args[0],args[1],args[2],args[3]);break;default:callback(...args);break}}catch(e){reportUncaughtException(e)}finally{@putInternalField(@asyncContext,0,restore)}}drainMicrotasks()}while(!queue.isEmpty())}@putInternalField(nextTickQueue,0,0),@putInternalField(nextTickQueue,1,queue),@putInternalField(nextTickQueue,2,processTicksAndRejections),setup=@undefined};function nextTick(cb,args){if(validateFunction(cb),setup)setup(),process=globalThis.process;if(process._exiting)return;queue.push({callback:cb,args:@argumentCount()>1?@Array.prototype.slice.@call(arguments,1):@undefined,frame:@getInternalField(@asyncContext,0)}),@putInternalField(nextTickQueue,0,1)}return nextTick})
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             ^
TypeError: Requested module is not instantiated yet.
      at processTicksAndRejections (:1:2602)

Steps to reproduce the Behavior

bun 1.0.0 library 0.63.0 bun .

melroy89 commented 10 months ago

I got the same problem. Very strange issue. Bun should be a drop-in replacement, maybe it's a bug in Bun. Could you create an issue at bun as well?

Elektroplayer commented 10 months ago

https://github.com/oven-sh/bun/issues/5144

melroy89 commented 10 months ago

Root cause is because we still use request-promise package! Which is outdated, has vurnabilities and now also doesn't work with bun...

See also: https://github.com/yagop/node-telegram-bot-api/issues/1076

Move away from request-promise asap! Plz.

melroy89 commented 9 months ago

Can somebody retest with Bun 1.0.2?

Elektroplayer commented 9 months ago

Tested for about five minutes. The bot starts and seems to work fine.