question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

build error: First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object

See original GitHub issue

Hi,

I have a project with an older version of cbor (5.0.1). First off, I have tried to update to the latest version (7.0.5) but that didn’t fix the issue, and yields another issue at build time, with rollup, so I’d rather not go down that path just yet.

The issue occurs in a jest environment, when testing the build code. That is, if I run a test against the source code, there is no issue and I get the correct output.

If I test against the build code, then this error arises:

First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object

with the stack call as follows

fromObject (dist/decoder-es.js:480:9)
      at from (dist/decoder-es.js:314:10)
      at new subarray (dist/decoder-es.js:290:10)
          at Uint8Array.subarray (<anonymous>)
      at Uint8Array.slice (dist/decoder-es.js:1249:19)
      at fromListPartial (dist/decoder-es.js:4209:26)
      at fromList (dist/decoder-es.js:4196:11)
      at NoFilter.Object.<anonymous>.Readable.read (dist/decoder-es.js:3746:20)
      at NoFilter.read (dist/decoder-es.js:8626:14)
      at Object.decode [as decodeFirstSync] (dist/decoder-es.js:10726:19)
      at decode (dist/decoder-es.js:30392:22)
      at Object.<anonymous> (test/build.es.test.js:7:24)

I have set up a repro here if that helps: https://github.com/lemoustachiste/repro-cbor-build. It seems to me that it was until recently working (albeit not in this repo), but I am not capable to identify what changed so maybe you can help me get on the right tracks.

The entry point is here: https://github.com/lemoustachiste/repro-cbor-build/blob/master/src/index.js#L97

Thanks

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:14 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
hildjjcommented, May 4, 2021

OK, i’ve got it. Use decode(encoded, {preferWeb: true}), then in the places where you are looking for Buffer, look for Uint8Array. The environment that the babel’d code is running in is using slightly different Buffer implementations, but the native Uint8Arrays will make it through all of that cleanly.

        if (value instanceof Uint8Array) {
            value = cbor.decode(value).toString('hex')
        }

        acc[key] = value
        return acc
    }, {})
}

export default function decode (base58string) {
    const encoded = multibase.decode(base58string)
    const map = cbor.decode(encoded, {preferWeb: true})
    const json = constructRootJSON(map)

    return json
}
0reactions
lemoustachistecommented, May 5, 2021

I have isolated the issue to the type of the value property, so even preferWeb is not required. For all intent of purposes I’d say this issue is resolved so I am going to close.

Thanks again @hildjj

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: The first argument must be one of type string, Buffer ...
TypeError : The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type object in cryptoJS.
Read more >
First argument must be a string, Buffer, ArrayBuffer, Array, or ...
I think problem is in buffer.js file - new Buffer() requires argument. You can create Buffer object outside class-transformer and then use ...
Read more >
ERROR: The first argument must be of type string or an ...
ERROR : The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received...
Read more >
How to fix a problem appearing on the token panel - RoboHero
On our token.robohero.io appears the following problem “Create Tx failed: First argument must be a string, Buffer, ArrayBuffer, Array, ...
Read more >
cypress-io/cypress - Gitter
Error: CypressError: TypeError: First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object. at fromObject (buffer.js:259:9) at ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found