fix(aws-lambda): add globalThis.crypto polyfill by naveentehrpariya · Pull Request #5024 · honojs/hono · GitHub
Skip to content

fix(aws-lambda): add globalThis.crypto polyfill#5024

Open
naveentehrpariya wants to merge 1 commit into
honojs:mainfrom
naveentehrpariya:fix-aws-lambda-crypto-polyfill
Open

fix(aws-lambda): add globalThis.crypto polyfill#5024
naveentehrpariya wants to merge 1 commit into
honojs:mainfrom
naveentehrpariya:fix-aws-lambda-crypto-polyfill

Conversation

@naveentehrpariya

Copy link
Copy Markdown

What

The aws-lambda adapter is missing the globalThis.crypto ??= crypto
polyfill that lambda-edge already ships (added in
lambda-edge/handler.ts:1,8).

Without it, handlers that call Web Crypto APIs
(crypto.randomUUID(), crypto.getRandomValues(), crypto.subtle.*)
will throw on Lambda runtimes where globalThis.crypto is not yet
natively available.

Closes item 3 of #5010.

Changes

  • src/adapter/aws-lambda/handler.ts — import node:crypto and set
    globalThis.crypto ??= crypto (same two lines as lambda-edge)
  • src/adapter/aws-lambda/handler.test.ts — add a
    globalThis.crypto polyfill describe block verifying the global is
    defined and randomUUID() returns a valid v4 UUID

Checklist

  • Tests added
  • Tests pass (npx vitest run src/adapter/aws-lambda/handler.test.ts → 34/34)
  • Formatted (bun run format)
  • TypeScript clean (npx tsc --noEmit)
  • ESLint clean (npx eslint src/adapter/aws-lambda/handler.ts src/adapter/aws-lambda/handler.test.ts)

The lambda-edge adapter already ships this polyfill so handlers can use
Web Crypto APIs (randomUUID, getRandomValues, subtle) without importing
node:crypto explicitly. The aws-lambda adapter was missing it.

Closes item 3 of honojs#5010.
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

Successfully merging this pull request may close these issues.

1 participant