workers-rs icon indicating copy to clipboard operation
workers-rs copied to clipboard

[BUG] RPC Method Proxy Issues: Export and Usability

Open alpgul opened this issue 2 months ago • 5 comments

RPC methods are being proxied, which makes usage difficult. In the index.d.ts file, export is specified, but the generated index.js exports a Proxy. This also causes a "not found" error, similar to the example. RPC methods should be moved outside the proxy.

https://github.com/cloudflare/workers-rs/blob/490c6c9082e06db5e29a6d622f37893628191396/worker-build/src/js/shim.js#L113

lib.rs:

#[wasm_bindgen]
pub async fn greet()

build/index.d.ts:

export function greet(): void;

demo.ts:

import {greet} from "./build/index.js" //throw error not found greet

alpgul avatar Oct 29 '25 13:10 alpgul

If you need directly exported functions, that you want to consume from JS, that is possible using the #wasm_bindgen attribute on the function.

Formally, RPC definitions do not imply an export of the underlying library, only the cloudflare RPC entry point configuration export.

Or am I misunderstanding the use case for importing here?

guybedford avatar Oct 29 '25 21:10 guybedford

I'm not using the default shim file. I'm using a custom shim. Therefore, I need to access the event and rpc methods using import. The generated build/index.d.ts file tells me that they are exported, but in the build/index.js file, the proxy is being exported. So there's an inconsistency.

alpgul avatar Oct 30 '25 09:10 alpgul

Custom shims are in the process of being deprecated to rather lean into the wasm bindgen macro customizations, although this process is ongoing.

I'd be interested to hear how and why you are using a custom shim here though, to figure out how we can ensure your use case is supported without custom shims.

guybedford avatar Oct 30 '25 16:10 guybedford

I'm using custom shims to use JavaScript and Rust code together. If the custom shims are deprecated, how can I use the two code structures together?

alpgul avatar Nov 01 '25 08:11 alpgul

I'm using custom shims to use JavaScript and Rust code together. If the custom shims are deprecated, how can I use the two code structures together?

Can you share more about the use case? The idea is that you could use standards Wasm Bindgen patterns instead - JS Snippets, declaring exports / imports, etc.

guybedford avatar Nov 03 '25 22:11 guybedford