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

🐛 BUG: Import #5 module="env" error #247

Closed
makorne opened this issue Nov 25, 2022 · 3 comments
Closed

🐛 BUG: Import #5 module="env" error #247

makorne opened this issue Nov 25, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@makorne
Copy link

makorne commented Nov 25, 2022

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:

serde = "1"
jsonwebtoken = "8"

In lib.rs:

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
@makorne makorne added the bug Something isn't working label Nov 25, 2022
@makorne makorne changed the title 🐛 BUG: 🐛 BUG: Import #5 module="env" error Nov 25, 2022
@rozenmd rozenmd transferred this issue from cloudflare/workers-sdk Nov 28, 2022
@zebp
Copy link
Collaborator

zebp commented Nov 28, 2022

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.

@zebp zebp closed this as completed Nov 28, 2022
Repository owner moved this from Untriaged to Done in workers-sdk Nov 28, 2022
@mikeumus
Copy link

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 😢

@21eleven
Copy link

I tried jwt-compact and that worked for me 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants