Skip to content

Buffer is not defined when using @aws-crypto/client-browser in a Web Worker #1616

@karimaounn

Description

@karimaounn

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

  1. Create an Angular app
  2. Install @aws-crypto/client-browser
  3. Move decryption logic into a Web Worker
  4. Call buildClient inside the worker

Environment:

  • Angular: 19.2.14
  • SDK: @aws-crypto/client-browser 4.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions