jhurliman/node-rate-limiter

Unexpected token '?'

xeroxstar opened this issue ยท 5 comments

I am running this example:

import { RateLimiter } from "limiter";

// Allow 150 requests per hour (the Twitter search limit). Also understands
// 'second', 'minute', 'day', or a number of milliseconds
const limiter = new RateLimiter({ tokensPerInterval: 150, interval: "hour" });

async function sendRequest() {
  // This call will throw if we request more than the maximum number of requests
  // that were set in the constructor
  // remainingRequests tells us how many additional requests could be sent
  // right this moment
  const remainingRequests = await limiter.removeTokens(1);
  callMyRequestSendingFunction(...);
}

and i am getting this error:

this.fireImmediately = fireImmediately ?? false;
                                                ^

SyntaxError: Unexpected token '?'

What environment are you running this in?

Same issue with NodeJS v12.3.1, Yarn 1.22.5 and Ubuntu 16.04.7.

What environment are you running this in?

node v12.13.0
npm v6.12
windows 10

I was able to fix the the module by replacing the line this.fireImmediately = fireImmediately ?? false; to this.fireImmediately = fireImmediately || false; in ratelimiter.js. But as I understand the module need to be compiled with "babel-plugin-proposal-nullish-coalescing-operator" to make it work without any changes to the files.

Thanks. I think the issue is targeting ESNext with the TypeScript -> JS compilation, which breaks support for node v12. I'll change the compilation target to ES2019.

Fixed in #79