Skip to content

TypeError occurs when using JWT Helpers with Bun #462

Open
@nzws

Description

@nzws

When using the JWT Helper from @mux/mux-node in the Bun runtime, the following error occurs:

10 |         throw new TypeError(`${types.join(' or ')} instances for symmetric algorithms must be of type "secret"`);
11 |     }
12 | };
13 | const asymmetricTypeCheck = (alg, key, usage) => {
14 |     if (!isKeyLike(key)) {
15 |         throw new TypeError(invalidKeyInput(alg, key, ...types));
                   ^
TypeError: Key for the RS256 algorithm must be of type CryptoKey. Received an instance of KeyObject
      at asymmetricTypeCheck (/Users/nzws/ghq/github.com/nzws/mux-node-sdk-bun-problem-repro/node_modules/jose/dist/browser/lib/check_key_type.js:15:15)
      at checkKeyType (/Users/nzws/ghq/github.com/nzws/mux-node-sdk-bun-problem-repro/node_modules/jose/dist/browser/lib/check_key_type.js:42:9)
      at /Users/nzws/ghq/github.com/nzws/mux-node-sdk-bun-problem-repro/node_modules/jose/dist/browser/jws/flattened/sign.js:52:9
      at sign (/Users/nzws/ghq/github.com/nzws/mux-node-sdk-bun-problem-repro/node_modules/jose/dist/browser/jws/flattened/sign.js:29:16)
      at /Users/nzws/ghq/github.com/nzws/mux-node-sdk-bun-problem-repro/node_modules/jose/dist/browser/jws/compact/sign.js:11:43
      at sign (/Users/nzws/ghq/github.com/nzws/mux-node-sdk-bun-problem-repro/node_modules/jose/dist/browser/jws/compact/sign.js:10:16)
      at sign (/Users/nzws/ghq/github.com/nzws/mux-node-sdk-bun-problem-repro/node_modules/jose/dist/browser/jwt/sign.js:10:16)

Running the same code in Node.js works without any issues. It seems that this error is due to jose using the build for browser environment when running in the Bun runtime, but the exact details are unclear.

Here is the repository to reproduce this issue: https://github.com/nzws/mux-node-sdk-bun-problem-repro

Environment

  • Bun: v1.1.20 (darwin arm)
  • @mux/mux-node: v8.8.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