Attempting to use this with Cloudflare Workers, I'm getting an error that buffer isn't defined. I suspect it's because Buffer isn't imported explicitly.
(base) mistial@Mistials-MacBook-Pro xxx % npx wrangler deploy
⛅️ wrangler 3.52.0
-------------------
Your worker has access to the following bindings:
- Queues:
- QUEUE: xxx
- D1 Databases:
- DB: xxx (xxx-xxx-xxx-xxx-xxx)
Total Upload: xxx KiB / gzip: xxx KiB
✘ [ERROR] A request to the Cloudflare API (/accounts/xxx/workers/scripts/xxx) failed.
Uncaught ReferenceError: Buffer is not defined
at null.<anonymous>
(file:///Users/mistial/Projects/xxx/node_modules/asn1-ts/source/asn1.ts:88:9) in toBytes
at null.<anonymous> (file:///Users/mistial/Projects/xxx/src/router.ts:12:26)
[code: 10021]
To ensure compatibility with a wider set of npm packages, and make it easier for you to run existing
applications on Cloudflare Workers, the following APIs from the Node.js runtime are available directly
as Workers runtime APIs, with no need to add polyfills to your own code
They show the need to add an import like import { Buffer } from 'node:buffer'; This seems to align with nodejs recommendations:
While the Buffer class is available within the global scope, it is still recommended to explicitly reference
it via an import or require statement.
Attempting to use this with Cloudflare Workers, I'm getting an error that buffer isn't defined. I suspect it's because Buffer isn't imported explicitly.
I am using nodejs compatibility mode:
Looking through the CloudFlare Documentation, it states:
They show the need to add an import like
import { Buffer } from 'node:buffer';
This seems to align with nodejs recommendations: