Agent-js stdlib.Uint8Array is not a constructor

What’s that agent-js error while trying to perform a query locally?

chunk-AL5F2A5A.js?v=8c176263:3155 Uncaught (in promise) TypeError: stdlib.Uint8Array is not a constructor
at decodeAsm (chunk-AL5F2A5A.js?v=8c176263:3155:18)
at new _Decoder (chunk-AL5F2A5A.js?v=8c176263:4972:23)
at new Uint8ArrayDecoder (chunk-AL5F2A5A.js?v=8c176263:6675:25)
at decode (chunk-AL5F2A5A.js?v=8c176263:6688:19)
at _HttpAgent.status (@dfinity_agent.js?v=0f04bff6:4504:12)
at async _HttpAgent.fetchRootKey (@dfinity_agent.js?v=0f04bff6:4508:23)
at async ve (actor.api.ts:40:5)
at async jt (satellite.api.ts:127:26)
at async HTMLButtonElement.version (admin.ts:8:5)

Node dependencies s*** as usual.

“Solved” by polyfilling the required stdlib.Uint8Array inherited by cbor using @esbuild-plugins/node-modules-polyfill.

If anyone lands on this in the future, note the above works out only for development.

Hi @peterparker , i’m getting the same problem, how exactly do I “polyfill” the required stdlib.Uint8Array inherited by cbor.

The solution depends what bundler you are using (vite, rollup, webpack etc.) - i.e. which plugin you gonna use and how you gonna use it is tailored for your bundler but, generally speaking, you have to configure your bundler with plugins to polyfill those NodeJS dependencies that are not meant for the browser.

1 Like