kriszyp/cbor-x

Incompatible with Bun.js?

Opened this issue · 4 comments

I trying to run with Bun.js, but getting this error. Also, I remapped imports. In deno is works (except console.log on some objects). In node.js remapping not supported (root directory).

82 |                    return this.encode(value, encodeOptions)
83 |            }
84 |
85 |            this.encode = function(value, encodeOptions)    {
86 |                    if (!target) {
87 |                            target = new ByteArrayAllocate(8192)
                 ^
TypeError: function is not a constructor (evaluating 'new ByteArrayAllocate(8192)')
      at /***/node_modules/cbor-x/encode.js:87:13

What version of Bun.js are you using? I believe this error was fixed in newer versions of Bun.

Meanwhile I found two strange or fundamental issues.

  1. "new" operator on "allocate" function is invalid.
  2. Existence of "Buffer" doesn't guarantee "allocate" exist

And its as minimum.
Here is potential fix for bun.js
9e36800

It is not too hard to fix, I've already done it in the msgpackr sibling package, but if it is already fixed, why not just use Bun.js with the fix?

still think that we should totally remove all node:Buffer and only stick to using Uint8Array