Problem
I have an Angular app using @aws-crypto/client-browser for decryption. It works fine in the main thread, but when I run it inside a Web Worker, I get: Uncaught ReferenceError: Buffer is not defined at build_cryptographic_key_helpers.js:6:21
This happens when calling: const { decrypt } = buildClient(CommitmentPolicy.REQUIRE_ENCRYPT_REQUIRE_DECRYPT);
Interestingly, Buffer.alloc() works when called directly in the worker, so it seems specific to how the SDK uses Buffer internally.
Possible Explanation
Since Buffer.alloc() works in the worker, this might be related to how the SDK bundles Buffer internally. Possibly Vite’s bundling behavior.
Steps to Reproduce
- Create an Angular app
- Install @aws-crypto/client-browser
- Move decryption logic into a Web Worker
- Call buildClient inside the worker
Environment:
- Angular: 19.2.14
- SDK: @aws-crypto/client-browser 4.0.0