SGrondin / bottleneck

Job scheduler and rate limiter, supports Clustering
MIT License
1.82k stars 75 forks source link

Webpacking bottleneck and the eval("require")("ioredis") obfuscation... #130

Closed cliffkoh closed 5 years ago

cliffkoh commented 5 years ago

I'm running into a problem now where because of the obfuscation over here: https://github.com/SGrondin/bottleneck/blob/63742224c8dd345a4d6752ac87ad1c597329edfd/src/IORedisConnection.coffee#L15

This require does not get properly replaced with a __webpack__require__ import, resulting in a failure to resolve "ioredis" at runtime...

Any advice?

cliffkoh commented 5 years ago

BTW the reason I am hitting this code path is because:

  1. I'm using ioredis for clustering
  2. I am webpacking all my loose files into 1 single bundle so nodejs startup is faster (because code is running on serverless)

In this case, I'm blocked by this pattern here..

cliffkoh commented 5 years ago

One idea to get around this is to refactor the constructor to allow passing in IORedis and if passed in, don't do this eval/require..

SGrondin commented 5 years ago

I like your idea and it can be a quick workaround until someone suggests a better solution. It's disappointing that the workaround to make things work in one environment breaks it for other people. I'll implement and release it tomorrow morning.

Edit: Another idea could be to look for the presence of the __webpack__require__ function. More automatic, but fragile.

cliffkoh commented 5 years ago

Thanks Simon!

SGrondin commented 5 years ago

I've released v2.19.3. It allows you to pass the { Redis: your_ioredis_module } option. Please let me know how it goes!

cliffkoh commented 5 years ago

Thank you!

cliffkoh commented 5 years ago

I noticed that TypeScript types were not updated so created a PR for it...

SGrondin commented 5 years ago

Sorry about that! That's what happens when I try to rush things. I've just released v2.19.4.

cliffkoh commented 5 years ago

No worries, appreciate how responsive you have been :)