simplyhexagonal / short-unique-id

Short Unique ID (UUID) generation library. Available in NPM.

Home Page:https://www.npmjs.com/package/short-unique-id

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use in Cloudflare worker?

mikecann opened this issue · comments

Im trying to use this lib in a cloudflare worker but am getting the following error

EvalError: Code generation from strings disallowed for this context
    at ShortUniqueId2.Function (<anonymous>)
    at new ShortUniqueId2 (C:\dev\me\tinkering-with-durable-objects\packages\server\dist\index.mjs:135:30)
    at generateShortId (C:\dev\me\tinkering-with-durable-objects\packages\server\dist\index.mjs:2076:15)
    at Object.auth.signup (C:\dev\me\tinkering-with-durable-objects\packages\server\dist\index.mjs:2422:22)
    at C:\dev\me\tinkering-with-durable-objects\packages\server\dist\index.mjs:2114:46
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at Object.handle (C:\dev\me\tinkering-with-durable-objects\packages\server\dist\index.mjs:50:22)
    at fetch (C:\dev\me\tinkering-with-durable-objects\packages\server\dist\index.mjs:2497:24)
    at EventsModule.dispatchFetch (C:\dev\me\tinkering-with-durable-objects\node_modules\miniflare\src\modules\events.ts:149:27)
    at Miniflare._Miniflare_httpRequestListener (C:\dev\me\tinkering-with-durable-objects\node_modules\miniflare\src\index.ts:408:20)

Thoughts?

Hi @mikecann , thanks for the report.

I had been scratching my head for the last couple of days in regards to this issue until I noticed that the docs are generated with an eval polyfill.

Since the docs had been included in the release of short-unique-id you are using I can see how it may be causing a false positive.

To make sure this issue properly goes away I have refactored the build process to use a better typescript transpiler that uses minimal polyfills and made sure only the dist and bin folders are included in the release package (no more pesky docs with eval polyfills).

Please try out v4.3.4 which has now been published and let us now if it fixes your issue.

Cheers 🍻

Oh wow thanks @jeanlescure for putting so much work into my innocent issue :)

It turns out however that Cloudflare Durable Objects IDs work differently to how I was expecting them to so I cant use this (or any) shortid lib to generate shorter UUIDs anyways because I cant then get the shortID back from within the DurableObject :(

So I really appreciate you going to so much effort with this however :)