TypeError: Value of "this" must be of type SubtleCrypto
See original GitHub issueWhen I run this simple code, it throws an error when running from miniflare. The same code works fine running from Cloudflare (or wrangler dev
without the --local
flag).
Code:
export default {
async fetch(request, env, ctx) {
const secret = new TextEncoder().encode('test')
const key = await crypto.subtle.importKey('raw', secret, { name: 'HMAC', hash: { name: 'SHA-512' } }, false, [
'sign',
'verify',
])
return new Response(JSON.stringify(key), { status: 200 })
},
}
Error:
TypeError: Value of "this" must be of type SubtleCrypto
at new NodeError (node:internal/errors:377:5)
at Proxy.importKey (node:internal/crypto/webcrypto:517:30)
at Object.fetch (/private/Users/leonardo/worker-test/src/index.ts:4:37)
at /Users/leonardo/worker-test/node_modules/@miniflare/core/src/standards/event.ts:331:19
at /Users/leonardo/worker-test/node_modules/@miniflare/shared/src/event.ts:29:9
at ServiceWorkerGlobalScope.<anonymous> (/Users/leonardo/worker-test/node_modules/@miniflare/shared/src/event.ts:77:9)
at ServiceWorkerGlobalScope.[nodejs.internal.kHybridDispatch] (node:internal/event_target:639:20)
at ServiceWorkerGlobalScope.dispatchEvent (node:internal/event_target:581:26)
at ServiceWorkerGlobalScope.dispatchEvent (/Users/leonardo/worker-test/node_modules/@miniflare/shared/src/event.ts:63:18)
at ServiceWorkerGlobalScope.dispatchEvent (/Users/leonardo/worker-test/node_modules/@miniflare/shared/src/event.ts:87:26)
Issue Analytics
- State:
- Created a year ago
- Reactions:4
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Error on importing a public key 'SubtleCrypto'
Uncaught (in promise) TypeError: Failed to execute 'importKey' on 'SubtleCrypto': The provided value cannot be converted to a sequence.
Read more >Web Crypto API | Node.js v19.3.0 Documentation
If represented as an <Object>, the object must have a name property whose value is one of the above listed values. ecdsaParams.name #....
Read more >SubtleCrypto.importKey() - Web APIs | MDN
Raised when keyUsages is empty but the unwrapped key is of type secret or private . TypeError. Raised when trying to use an...
Read more >SubtleCrypto in web_sys - Rust
The `SubtleCrypto` class. ... pub struct SubtleCrypto { /* private fields */ }. Expand description ... Tests whether the type of this JS...
Read more >Web Crypto · Cloudflare Workers docs
The Web Crypto API is implemented through the SubtleCrypto interface ... code that relies on Node's Crypto API, you will need to adapt...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey! I’ve just released version
2.5.0
with this fix. Please let me know if you have any other issues.Even on 2.5.0, this error is still occurring for me.