Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError occurs when using JWT Helpers with Bun #462

Open
nzws opened this issue Jul 27, 2024 · 0 comments
Open

TypeError occurs when using JWT Helpers with Bun #462

nzws opened this issue Jul 27, 2024 · 0 comments

Comments

@nzws
Copy link

nzws commented Jul 27, 2024

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant