You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use jsonwebtoken::{ encode, Header, EncodingKey };
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
struct Claims {
sub: String,
}
In main():
let my_claims = Claims {
sub: "[email protected]".to_owned(),
};
let token = encode(&Header::default(), &my_claims, &EncodingKey::from_secret("secret".as_ref())).unwrap();
And get this error:
TypeError: WebAssembly.Instance(): Import cloudflare/wrangler2#5 module="env" error: module is not an object or function
at /home/dan/cloudflare/rustwasm-worker-template/build/worker/shim.mjs:1:2975
at SourceTextModule.evaluate (node:internal/vm/module:224:23)
at VMScriptRunner.runAsModule (/home/dan/cloudflare/node_modules/wrangler/node_modules/@miniflare/runner-vm/src/index.ts:38:18)
at VMScriptRunner.run (/home/dan/cloudflare/node_modules/wrangler/node_modules/@miniflare/runner-vm/src/index.ts:82:17)
at Miniflare.#reload (/home/dan/cloudflare/node_modules/@miniflare/core/src/index.ts:775:13)
at Miniflare.getPlugins (/home/dan/cloudflare/node_modules/@miniflare/core/src/index.ts:1017:5)
at createServer (/home/dan/cloudflare/node_modules/wrangler/node_modules/@miniflare/http-server/src/index.ts:369:19)
✘ [ERROR] Miniflare process exited with code 1
The text was updated successfully, but these errors were encountered:
This is because ring currently doesn't support WASM so it's trying to link some C that it compiles which doesn't work on the WASM target. You might have some luck with jwt-compact which seems to support WASM, I got a similar example to yours working without any issues. If that still doesn't work it might be time to try writing your Worker in TypeScript and use a library like workers-jwt.
I tried porting what I had over to jwt-compact and my routes stopped responding with anything. It was weird. Other get/post routes would but couldn't log even the beginning of a .post route (non-async nor async). It's sad that Workers is Javascript under the hood and not just Rust. I have to find some other cloud provider now 😢
What version of
Wrangler
are you using?2.4.4
What operating system are you using?
Fedora 36
Describe the Bug
I add to rustwasm-worker-template the following:
In dependences:
In lib.rs:
In main():
And get this error:
The text was updated successfully, but these errors were encountered: